New Users: Quick MySQL: Difference between revisions

m
no edit summary
mNo edit summary
mNo edit summary
 
Line 23: Line 23:


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.
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.
'''''Note'':''' Windows 7 users 
* For '''$dbhost''' use 127.0.0.1 and not localhost
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


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
Line 34: Line 38:


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== PHP Connect ==
== PHP Connect ==
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:
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:
Line 64: Line 69:
|style="background:#f5f5f5;"|
|style="background:#f5f5f5;"|
<pre style="border:0;margin:0;padding:0">
<pre style="border:0;margin:0;padding:0">
<? // Database configuration file config_db.php
<?php  // Database configuration file config_db.php
$dbhost = 'localhost'; //server name localhost or 127.0.0.1
$dbhost = 'localhost'; //server name localhost or 127.0.0.1
$dbuser = 'root';      //User name default root  
$dbuser = 'root';      //User name default root  
Line 77: Line 82:
|style="background:#f5f5f5;"|
|style="background:#f5f5f5;"|
<pre style="border:0;margin:0;padding:0">
<pre style="border:0;margin:0;padding:0">
<? // Open database open_db.php
<?php // Open database open_db.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
?>
?>
Line 88: Line 93:
|style="background:#f5f5f5;"|
|style="background:#f5f5f5;"|
<pre style="border:0;margin:0;padding:0">
<pre style="border:0;margin:0;padding:0">
<? // Close database close_db.php
<?php  // Close database close_db.php
mysql_close($conn);
mysql_close($conn);
?>
?>
Line 108: Line 113:
<body>
<body>
<p>Quick db test</p>
<p>Quick db test</p>
<?
<?php
include 'config_db.php';
include 'config_db.php';
include 'open_db.php';
include 'open_db.php';
Line 166: Line 171:
<body>
<body>
<p>Quick db test</p>
<p>Quick db test</p>
<?
<?php
include 'config_db.php';
include 'config_db.php';
include 'open_db.php';
include 'open_db.php';
Line 206: Line 211:
|style="background:#f5f5f5;"|
|style="background:#f5f5f5;"|
<pre style="border:0;margin:0;padding:0">
<pre style="border:0;margin:0;padding:0">
<?
<?php
// Database configuration file config2_db.php
// Database configuration file config2_db.php
$dbhost = 'localhost'; //server name localhost or 127.0.0.1
$dbhost = 'localhost'; //server name localhost or 127.0.0.1
Line 221: Line 226:
|style="background:#f5f5f5;"|
|style="background:#f5f5f5;"|
<pre style="border:0;margin:0;padding:0">
<pre style="border:0;margin:0;padding:0">
<?
<?php
// Open database open2_db.php
// Open database open2_db.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
Line 234: Line 239:
|style="background:#f5f5f5;"|
|style="background:#f5f5f5;"|
<pre style="border:0;margin:0;padding:0">
<pre style="border:0;margin:0;padding:0">
<?
<?php
// Close database close2_db.php
// Close database close2_db.php
mysql_close($conn);
mysql_close($conn);
Line 261: Line 266:
<body>
<body>
<p>Quick db contacts</p>
<p>Quick db contacts</p>
<?
<?php
include 'config2_db.php';
include 'config2_db.php';
include 'open2_db.php';
include 'open2_db.php';
Line 304: Line 309:
<body>
<body>
<p>Quick db contacts</p>
<p>Quick db contacts</p>
<?
<?php
include 'config2_db.php';
include 'config2_db.php';
include 'open2_db.php';
include 'open2_db.php';
Line 341: Line 346:
<body>
<body>
<p>Quick db contacts</p>
<p>Quick db contacts</p>
<?
<?php
include 'config2_db.php';
include 'config2_db.php';
include 'open2_db.php';
include 'open2_db.php';
Line 382: Line 387:
<body>
<body>
<p>Quick db contacts</p>
<p>Quick db contacts</p>
<?
<?php
include 'config2_db.php';
include 'config2_db.php';
include 'open2_db.php';
include 'open2_db.php';
Line 417: Line 422:
<body>
<body>
<h2 align="center">Quick db contacts</h2>
<h2 align="center">Quick db contacts</h2>
<?
<?php
include 'config2_db.php';
include 'config2_db.php';
include 'open2_db.php';
include 'open2_db.php';
Line 427: Line 432:
<tr><td><b>Name</b></td><td><b>Address</b></td></tr>
<tr><td><b>Name</b></td><td><b>Address</b></td></tr>


<?
<?php
while(list($name,$email)= mysql_fetch_row($result)){
while(list($name,$email)= mysql_fetch_row($result)){
  echo "<tr><td>$name</td><td>$email</td></tr>";
  echo "<tr><td>$name</td><td>$email</td></tr>";
Line 450: Line 455:


{|  
{|  
| [[Image:uc_small_logo.gif]] || [[User:Ric|Ric]]
| [[Image:uc_small_logo.gif]] || [[User:WikiSysop|Ric]]
|}
|}


[[Category: UniCenter]]
[[Category: UniCenter]]
[[Category: New Users]]
[[Category: New Users]]
[[Category: MySQL]]
[[Category: MySQL]]