https://wiki.uniformserver.com/index.php?title=New_Users:_Quick_MySQL&feed=atom&action=history
New Users: Quick MySQL - Revision history
2024-03-29T06:39:59Z
Revision history for this page on the wiki
MediaWiki 1.41.0
https://wiki.uniformserver.com/index.php?title=New_Users:_Quick_MySQL&diff=4273&oldid=prev
Ric at 16:03, 2 July 2010
2010-07-02T16:03:19Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 16:03, 2 July 2010</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l23">Line 23:</td>
<td colspan="2" class="diff-lineno">Line 23:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>You can administer the MySQL server using a [[MySQL Console | command line]] interface however Uniform Server includes [[MySQL phpMyAdmin | phpMyAdmin]] greatly easing this task. This section looks at accessing the server and database using PHP.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>You can administer the MySQL server using a [[MySQL Console | command line]] interface however Uniform Server includes [[MySQL phpMyAdmin | phpMyAdmin]] greatly easing this task. This section looks at accessing the server and database using PHP.</div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">'''''Note'':''' Windows 7 users </ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* For '''$dbhost''' use 127.0.0.1 and not localhost </ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">If you wish to use localhost check out [[5.0-Nano: Known Issues#MySQL host name 127.0.0.1 or localhost | MySQL host name 127.0.0.1 or localhost]] for a solution</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>'''''[[#top | Top]]'''''</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>'''''[[#top | Top]]'''''</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l34">Line 34:</td>
<td colspan="2" class="diff-lineno">Line 38:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>'''''[[#top | Top]]'''''</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>'''''[[#top | Top]]'''''</div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== PHP Connect ==</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== PHP Connect ==</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>MySQL is a server in its own right hence it has a host name associated with it. In addition it is an authenticated server meaning in order to allow access to a database it requires a user name and password. PHP uses one function to make a connection:</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>MySQL is a server in its own right hence it has a host name associated with it. In addition it is an authenticated server meaning in order to allow access to a database it requires a user name and password. PHP uses one function to make a connection:</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l64">Line 64:</td>
<td colspan="2" class="diff-lineno">Line 69:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><? // Database configuration file config_db.php</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php </ins>// Database configuration file config_db.php</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$dbhost = 'localhost'; //server name localhost or 127.0.0.1</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$dbhost = 'localhost'; //server name localhost or 127.0.0.1</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$dbuser = 'root'; //User name default root </div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$dbuser = 'root'; //User name default root </div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l77">Line 77:</td>
<td colspan="2" class="diff-lineno">Line 82:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><? // Open database open_db.php</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php </ins>// Open database open_db.php</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>?></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>?></div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l88">Line 88:</td>
<td colspan="2" class="diff-lineno">Line 93:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><? // Close database close_db.php</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php </ins>// Close database close_db.php</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>mysql_close($conn);</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>mysql_close($conn);</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>?></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>?></div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l108">Line 108:</td>
<td colspan="2" class="diff-lineno">Line 113:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db test</p></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db test</p></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config_db.php';</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open_db.php';</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l166">Line 166:</td>
<td colspan="2" class="diff-lineno">Line 171:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db test</p></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db test</p></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config_db.php';</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open_db.php';</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l206">Line 206:</td>
<td colspan="2" class="diff-lineno">Line 211:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>// Database configuration file config2_db.php</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>// Database configuration file config2_db.php</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$dbhost = 'localhost'; //server name localhost or 127.0.0.1</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$dbhost = 'localhost'; //server name localhost or 127.0.0.1</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l221">Line 221:</td>
<td colspan="2" class="diff-lineno">Line 226:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>// Open database open2_db.php</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>// Open database open2_db.php</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l234">Line 234:</td>
<td colspan="2" class="diff-lineno">Line 239:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|style="background:#f5f5f5;"|</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre style="border:0;margin:0;padding:0"></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>// Close database close2_db.php</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>// Close database close2_db.php</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>mysql_close($conn);</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>mysql_close($conn);</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l261">Line 261:</td>
<td colspan="2" class="diff-lineno">Line 266:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db contacts</p></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db contacts</p></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config2_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config2_db.php';</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open2_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open2_db.php';</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l304">Line 304:</td>
<td colspan="2" class="diff-lineno">Line 309:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db contacts</p></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db contacts</p></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config2_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config2_db.php';</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open2_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open2_db.php';</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l341">Line 341:</td>
<td colspan="2" class="diff-lineno">Line 346:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db contacts</p></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db contacts</p></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config2_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config2_db.php';</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open2_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open2_db.php';</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l382">Line 382:</td>
<td colspan="2" class="diff-lineno">Line 387:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db contacts</p></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><p>Quick db contacts</p></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config2_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config2_db.php';</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open2_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open2_db.php';</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l417">Line 417:</td>
<td colspan="2" class="diff-lineno">Line 422:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><body></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><h2 align="center">Quick db contacts</h2></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><h2 align="center">Quick db contacts</h2></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config2_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'config2_db.php';</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open2_db.php';</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>include 'open2_db.php';</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l427">Line 427:</td>
<td colspan="2" class="diff-lineno">Line 432:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><tr><td><b>Name</b></td><td><b>Address</b></td></tr></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><tr><td><b>Name</b></td><td><b>Address</b></td></tr></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><?</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><?<ins style="font-weight: bold; text-decoration: none;">php</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>while(list($name,$email)= mysql_fetch_row($result)){</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>while(list($name,$email)= mysql_fetch_row($result)){</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> echo "<tr><td>$name</td><td>$email</td></tr>";</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> echo "<tr><td>$name</td><td>$email</td></tr>";</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l450">Line 450:</td>
<td colspan="2" class="diff-lineno">Line 455:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{| </div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{| </div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>| [[Image:uc_small_logo.gif]] || [[User:<del style="font-weight: bold; text-decoration: none;">Ric</del>|Ric]]</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>| [[Image:uc_small_logo.gif]] || [[User:<ins style="font-weight: bold; text-decoration: none;">WikiSysop</ins>|Ric]]</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|}</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|}</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category: UniCenter]]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category: UniCenter]]</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category: New Users]]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category: New Users]]</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category: MySQL]]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category: MySQL]]</div></td></tr>
</table>
Ric
https://wiki.uniformserver.com/index.php?title=New_Users:_Quick_MySQL&diff=2928&oldid=prev
Ric at 21:42, 26 May 2008
2008-05-26T21:42:22Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 21:42, 26 May 2008</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l4">Line 4:</td>
<td colspan="2" class="diff-lineno">Line 4:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>| [[Image:uc_small_logo.gif | MPG UniCenter]] ||</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>| [[Image:uc_small_logo.gif | MPG UniCenter]] ||</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>New Users: </div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>New Users: </div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[New Users: Home <del style="font-weight: bold; text-decoration: none;">3.5-Apollo </del>| Home]] | </div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[New Users: Home | Home]] | </div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[New Users: Quick MySQL | Quick MySQL]] | </div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[New Users: Quick MySQL | Quick MySQL]] | </div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[New Users: Quick MySQL Info | Quick MySQL Info]]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[New Users: Quick MySQL Info | Quick MySQL Info]]</div></td></tr>
</table>
Ric
https://wiki.uniformserver.com/index.php?title=New_Users:_Quick_MySQL&diff=2925&oldid=prev
Ric: New page: <span id="top"></span> <div style="padding:0;margin:0; border-bottom:3px inset #000000"> {| | MPG UniCenter || New Users: [[New Users: Home 3.5-Apollo | Hom...
2008-05-26T21:36:36Z
<p>New page: <span id="top"></span> <div style="padding:0;margin:0; border-bottom:3px inset #000000"> {| | <a href="/File:Uc_small_logo.gif" title="File:Uc small logo.gif"> MPG UniCenter</a> || New Users: [[New Users: Home 3.5-Apollo | Hom...</p>
<p><b>New page</b></p><div><span id="top"></span><br />
<div style="padding:0;margin:0; border-bottom:3px inset #000000"><br />
{| <br />
| [[Image:uc_small_logo.gif | MPG UniCenter]] ||<br />
New Users: <br />
[[New Users: Home 3.5-Apollo | Home]] | <br />
[[New Users: Quick MySQL | Quick MySQL]] | <br />
[[New Users: Quick MySQL Info | Quick MySQL Info]]<br />
|}<br />
</div><br />
{| cellpadding="2"<br />
|<br />
__TOC__<br />
||<br />
'''Quick MySQL 3.5-Apollo'''<br />
|}<br />
So you have played with PHP may even have read the [[New Users: Quick PHP CGI | Quick PHP guide]] and now want to talk to MySQL using PHP. I have written this page purely for orientation with reference to Uniform Server, it is not intended in any way to teach you MySQL you can find better material on the Internet. Its sole purpose is to get you up and running with MySQL on Uniform Server hence it is a very basic introduction.<br />
<br />
Where is the on-off switch for MySQL? When you start Uniform Server 3.5-Apollo it automatically starts both the MySQL and Apache servers.<br />
<br />
== Introduction ==<br />
MySQL is an open-source DBMS it integrates with PHP they are the worlds most popular duo and effectively drive the Internet. MySQL is a collection of tables with various selectable handlers the default being MyISAM this provides for fast reading with slightly slower writing.<br />
<br />
You can administer the MySQL server using a [[MySQL Console | command line]] interface however Uniform Server includes [[MySQL phpMyAdmin | phpMyAdmin]] greatly easing this task. This section looks at accessing the server and database using PHP.<br />
<br />
'''''[[#top | Top]]'''''<br />
=== Security ===<br />
The MySQL server is a secure production server however it should be noted that the '''default installation''' is '''insecure''' this is because the user root name and password are universally know. (Well if it wasn't you would not be able to access your server, now would be a good time to change the '''[[New Users: Security#MySQL Server Configuration | MySQL root password ]]'''). Note for the examples on this page I have set my root password to '''fred123''' when you see this substitute your own password accordingly. <br />
<br />
=== How to use PHP to connect to MySQL server ===<br />
Every one has their own way of doing things I will explain my preferred method of connecting to the MySQL server use whatever method you are happy with. The following examples are intended only to confirm operation of the MySQL server.<br />
<br />
I prefer to do things in little snippets, when it comes to MySQL I think connect, open, do something and then close. The follow explains why In quick PHP I mentioned include external files in a nut shell I use them to implement my little snippets. Its a personal preference you are free to use whatever you like.<br />
<br />
'''''[[#top | Top]]'''''<br />
== PHP Connect ==<br />
MySQL is a server in its own right hence it has a host name associated with it. In addition it is an authenticated server meaning in order to allow access to a database it requires a user name and password. PHP uses one function to make a connection:<br />
<br />
* '''mysql_connect($dbhost, $dbuser, $dbpass)'''<br />
:* '''$dbhost''' Host name: The server is running locally on Uniserver hence can be either localhost or 127.0.0.1<br />
:* '''$dbuser''' User name: Uniserver default is root<br />
:* '''$dbpass''' User password: Uniserver default is root — I will be using fred123<br />
<br />
With a connection established it is equally easy to connect to a database with the following PHP function:<br />
<br />
* '''mysql_select_db($dbname)'''<br />
:* '''$dbname''' Database name<br />
<br />
Once you have finished with the database close it using the following PHP function:<br />
<br />
* '''mysql_close($conn)'''<br />
:* '''$conn''' This is an handle (reference) return by the connect function.<br />
<br />
'''''Note:''''' When your script ends PHP will automatically close all database connections so strictly speaking you do not have to specifically close the connection.<br />
<br />
You can embed the above in your code however when you need to change the connection or database it can become a pain hence I pop these functions into external files (scripts) as follows:<br />
<br />
=== Scripts — Note these are not the final scripts ===<br />
These are not the final scripts I am slowly building these up over the next few sections.<br />
<br />
Create a new text page and name it '''config_db.php''' copy the following code into it:<br />
<br />
{| width="80%" cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<? // Database configuration file config_db.php<br />
$dbhost = 'localhost'; //server name localhost or 127.0.0.1<br />
$dbuser = 'root'; //User name default root <br />
$dbpass = 'fred123s'; //Password default root -- I will be using ''fred123''<br />
?><br />
</pre><br />
|}<br />
<br />
Create a new text page and name it '''open_db.php''' copy the following code into it:<br />
<br />
{| width="80%" cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<? // Open database open_db.php<br />
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');<br />
?><br />
</pre><br />
|}<br />
<br />
Create a new text page and name it '''close_db.php''' copy the following code into it:<br />
<br />
{| width="80%" cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<? // Close database close_db.php<br />
mysql_close($conn);<br />
?><br />
</pre><br />
|}<br />
<br />
Save the above scripts in folder '''www''' (path *\Uniform Server\udrive\www)<br />
<br />
=== Using the scripts ===<br />
Using the scripts is straightforward for example:<br />
<br />
Create a new text page and name it '''test_db.php''' copy the following code into it:<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<html><br />
<title>Test db</title><br />
<body><br />
<p>Quick db test</p><br />
<?<br />
include 'config_db.php';<br />
include 'open_db.php';<br />
//do something to database, etc<br />
include 'close_db.php';<br />
?><br />
</body><br />
</html><br />
</pre><br />
|}<br />
<br />
Save the script in folder '''www'''<br />
Display the page by typing '''<nowiki>http://localhost/test_db.php</nowiki>''' into your browser address bar.<br />
<br />
=== Results ===<br />
With luck you will receive an error messages I trust not because of typos the above was a copy and past exercise.<br />
<br />
The warning is due to an error I introduced in '''config_db.php''' take a look at line $dbpass = 'fred123s'; it should read $dbpass = 'fred123';<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#ffffcc;"|<br />
'''Warning:''' mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in W:\www\open_db.php on line 2<br>Error connecting to mysql<br />
|}<br />
<br />
I introduced the error to show you the warning message note the '''line number''' and '''file name''' they provide a clue where to look for the bug in your code.<br />
<br />
Correct the bug ('''remove the offending s''' from the password in config_db.php ) and re-run the script, this time there will be no errors. You will see the message "Quick db test".<br />
<br />
You can create a database using [[MySQL phpMyAdmin | phpMyAdmin]] but we do not want to take this easy option lets do it the PHP way. <br />
<br />
'''''[[#top | Top]]'''''<br />
== Creating a Database ==<br />
In the previous section I implied it was difficult to create a database using PHP. Well I lied it takes only one line of code.<br />
<br />
'''Creating a database'''<br />
<br />
There are several ways to do this I prefer to run a query on the database using the SQL command '''CREATE DATABASE''' followed by the database name to be created. Sure you can use one line for this but I like to construct a query string first and then pass it to the PHP function or is that a method who cares its only terminology. The two lines look like this:<br />
<br />
* '''$query = "CREATE DATABASE mpg_test";'''<br />
* '''$result = mysql_query($query);'''<br />
<br />
The first line creates a variable '''$query''' this is assigned (made equal) to the string in quotes, the SQL command is '''CREATE DATABASE''' followed by the name of the database to be created mpg_test.<br />
<br />
The second line is interesting, you pop the string '''$query''' into the php function '''mysql_query()''' and it goes off and creates your database.<br />
<br />
Well never trust anyone or functions, always test to see if something happened. If the database was created then you can connect to it. Take this new code snippet, the last line of code checks for a connection it kills the program and displays '''Cannot select database''' if it fails to connect.<br />
<br />
'''New code'''<br />
<br />
Change your old '''test_db.php''' to this and save it to a new file '''test2_db.php''':<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<html><br />
<title>Test db 2</title><br />
<body><br />
<p>Quick db test</p><br />
<?<br />
include 'config_db.php';<br />
include 'open_db.php';<br />
$query = "CREATE DATABASE mpg_test";<br />
$result = mysql_query($query);<br />
mysql_select_db('mpg_test') or die('Cannot select database'); <br />
include 'close_db.php';<br />
?><br />
</body><br />
</html><br />
</pre><br />
|}<br />
<br />
View the page in your browser you can confirm the database was created by using apanel and running phpMyAdmin (if this is already running refresh your browser to see the new changes). To the left of phpMyAdmin you will see a drop down menu click on the down arrow you will find mpg_test(0) listed note (0) indicates no tables in the database.<br />
<br />
<br />
=== Delete a database ===<br />
Deleting a database is similar to the above use the '''DROP DATABASE SQL''' command.<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
$query = 'DROP DATABASE mpg_test';<br />
$result = mysql_query($query);<br />
</pre><br />
|}<br />
<br />
In general you do not spend time creating or deleting databases invariably you manipulate a database in the next section I show the final scripts that allow access to a named database<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Finished Scripts. ==<br />
Once you have created a database most of your time will be spent processing its data. I have modified the scripts to reflect this, they now target a specific database.<br />
<br />
=== Scripts ===<br />
'''config2_db.php''' Configuration file now '''includes''' the '''database name'''.<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<?<br />
// Database configuration file config2_db.php<br />
$dbhost = 'localhost'; //server name localhost or 127.0.0.1<br />
$dbuser = 'root'; //User name default root<br />
$dbpass = 'fred123'; //Replace with your root password'<br />
$dbname = 'mpg_test' //Replace with your database name<br />
?><br />
</pre><br />
|}<br />
<br />
'''open2_db.php''' Connects to server and selects a database<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<?<br />
// Open database open2_db.php<br />
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');<br />
mysql_select_db($dbname) or die('Cannot select database');<br />
?><br />
</pre><br />
|}<br />
<br />
'''close2_db.php''' No change:<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<?<br />
// Close database close2_db.php<br />
mysql_close($conn);<br />
?><br />
</pre><br />
|}<br />
<br />
Save the scripts in folder '''www'''<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
=== Using the scripts ===<br />
Using the scripts is straightforward the next example shows how to create a contact list table:<br />
<br />
<br />
== Creating a Table ==<br />
The following shows how to use the scripts to connect to the MySQL server and create a table in the database '''mpg_test'''<br />
<br />
Save the following as '''test3_db.php'''<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<html><br />
<title>Test db 3</title><br />
<body><br />
<p>Quick db contacts</p><br />
<?<br />
include 'config2_db.php';<br />
include 'open2_db.php';<br />
<br />
$query = 'CREATE TABLE contactlist( '.<br />
'clid INT NOT NULL AUTO_INCREMENT, '.<br />
'clname VARCHAR(50) NOT NULL, '.<br />
'clemail VARCHAR(50) NOT NULL, '.<br />
'clsubject VARCHAR(50) NOT NULL, '.<br />
'clmessage TEXT NOT NULL, '.<br />
'PRIMARY KEY(clid))';<br />
$result = mysql_query($query);<br />
<br />
include 'close2_db.php';<br />
?><br />
</body><br />
</html><br />
</pre><br />
|}<br />
<br />
The includes (include config_db.php and include open_db.php) open the database.<br><br />
A query string CREATE TABLE is used to create a table containing a contact list.<br><br />
Finally the database is closed using include close_db.php<br />
<br />
Display the page by typing '''<nowiki>http://localhost/test3_db.php</nowiki>''' into your browser address bar. This creates the table '''contactlist''' check using '''''phpMyAdmin'''''.<br />
<br />
To the left of phpMyAdmin you will see a drop down menu click on the down arrow you will find mpg_test(1) listed note (1) indicates there is one table in the database. From the drop down menu click on mpg_test(1) and the table will display on the right. The table has no data hence records are set to zero.<br />
<br />
With the table created adding data into it is again straightforward.<br />
<br />
'''''[[#top | Top]]'''''<br />
== Adding data to table ==<br />
Adding data to the table created in the example above is accomplished using the '''INSERT INTO''' command. This crude example shows two entries:<br />
<br />
Save the following as '''test4_db.php'''<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<html><br />
<title>Test db 4</title><br />
<body><br />
<p>Quick db contacts</p><br />
<?<br />
include 'config2_db.php';<br />
include 'open2_db.php';<br />
<br />
$query = "INSERT INTO contactlist (clname,clemail)VALUES ('fred1','fred1@int.com')";<br />
mysql_query($query) or die('Error, query failed');<br />
$query = "INSERT INTO contactlist (clname,clemail)VALUES ('fred2','fred2@int.com')";<br />
mysql_query($query) or die('Error, query failed');<br />
<br />
include 'close2_db.php';<br />
?><br />
</body><br />
</html><br />
</pre><br />
|}<br />
<br />
Display the page by typing '''<nowiki>http://localhost/test4_db.php</nowiki>''' into your browser address bar. This populates the table '''contactlist''' with two records '''fred1''' and '''fred2''' check using phpMyAdmin.<br />
<br />
To the left of phpMyAdmin you will see a drop down menu click on the down arrow you will find mpg_test(1) listed note (1) indicates there is one table in the database. From the drop down menu click on mpg_test(1) and the table will display on the right.<br />
<br />
Back to the left menu you will see '''contactlist''' displayed click on this and and then on browse in the right window top left, this will display the two records and the data entered.<br />
<br />
With the data inserted there are several ways to retrieve it.<br />
<br />
'''''[[#top | Top]]'''''<br />
== Reading Data Example 1 ==<br />
Reading data from the database<br />
<br />
Save the following as '''test5_db.php'''<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<html><br />
<title>Test db 5</title><br />
<body><br />
<p>Quick db contacts</p><br />
<?<br />
include 'config2_db.php';<br />
include 'open2_db.php';<br />
<br />
$query = "SELECT clname, clemail FROM contactlist";<br />
$result = mysql_query($query) or die('Error, query failed');<br />
<br />
while($row = mysql_fetch_array($result, MYSQL_ASSOC))<br />
{<br />
echo "Name = {$row['clname']} " .<br />
"Email = {$row['clemail']} <br>";<br />
} <br />
include 'close2_db.php';<br />
?><br />
</body><br />
</html><br />
</pre><br />
|}<br />
<br />
The '''while()''' loop will keep fetching new rows until mysql_fetch_array() returns FALSE, no more rows to read. The content of the rows are assigned to the variable $row and the values in row are then printed.<br />
<br />
'''MYSQL_ASSOC''' the second argument to mysql_fetch_array(), returns the row as an associative array. With an associative array you can access the field by using their name instead of using the index.<br />
<br />
Display the page by typing '''<nowiki>http://localhost/test5_db.php</nowiki>''' into your browser address bar.<br />
<br />
When I am faced with all them curly braces it drives me crazy I prefer the next method<br />
<br />
'''''[[#top | Top]]'''''<br />
== Reading Data Example 2 ==<br />
This is my preferred way to read data from a database:<br />
It uses the list() function to assign values to a list of variables, this is accomplished in one operation.<br />
<br />
Save the following as '''test6_db.php'''<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<html><br />
<title>Test db 6</title><br />
<body><br />
<p>Quick db contacts</p><br />
<?<br />
include 'config2_db.php';<br />
include 'open2_db.php';<br />
<br />
$query = "SELECT clname, clemail FROM contactlist";<br />
$result = mysql_query($query) or die('Error, query failed');<br />
<br />
while(list($name,$email)= mysql_fetch_row($result))<br />
{<br />
echo "Name :$name " .<br />
"Email : $email <br>";<br />
} <br />
include 'close2_db.php';<br />
?><br />
</body><br />
</html><br />
</pre><br />
|}<br />
<br />
The '''list() function''' assigns the named variables '''$name''' and '''$email''' in the order returned by '''mysql_fetch_row()'''.<br />
Now you can use the variables where you like.<br />
<br />
Display the page by typing '''<nowiki>http://localhost/test6_db.php</nowiki>''' into your browser address bar.<br />
<br />
'''''[[#top | Top]]'''''<br />
== Conclusion ==<br />
One final example to show how easy it is to mix PHP and HTML save the following as '''test7_db.php'''<br />
<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|style="background:#f5f5f5;"|<br />
<pre style="border:0;margin:0;padding:0"><br />
<html><br />
<title>Test db 7</title><br />
<body><br />
<h2 align="center">Quick db contacts</h2><br />
<?<br />
include 'config2_db.php';<br />
include 'open2_db.php';<br />
$query = "SELECT clname, clemail FROM contactlist";<br />
$result = mysql_query($query) or die('Error, query failed');<br />
?><br />
<br />
<table align="center" cellpadding="6" border="1"><br />
<tr><td><b>Name</b></td><td><b>Address</b></td></tr><br />
<br />
<?<br />
while(list($name,$email)= mysql_fetch_row($result)){<br />
echo "<tr><td>$name</td><td>$email</td></tr>";<br />
} <br />
include 'close2_db.php';<br />
?><br />
</table><br />
<br />
</body><br />
</html><br />
</pre><br />
|}<br />
<br />
The while loop now outputs table rows with each row containing '''$name''' and email '''$email'''.<br />
<br />
<br />
The above examples barley scratch the surface they serve as a starting point, I trust they have given you a feel for the power of both MySQL and PHP.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
----<br />
<br />
{| <br />
| [[Image:uc_small_logo.gif]] || [[User:Ric|Ric]]<br />
|}<br />
<br />
<br />
[[Category: UniCenter]]<br />
[[Category: New Users]]<br />
[[Category: MySQL]]</div>
Ric