Jump to content

[SOLVED] MySQL connecting problem


mindspin311

Recommended Posts

I have the following code that will not work. I tried using pear::db, then commented that out and just tried a simple example to get it to work. I even updated to PHP 5.2 just in case the 4.4 version was having problems with pear::db.

 

<?

$user="minds004_chris";
$password="password";
$database="minds004_students";
$host = "mindspingames.com";
mysql_connect($host,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,
               last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,
               email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
mysql_query($query);
mysql_close();

?>

/*
$limit = 5;
require_once 'DB.php';
$user = 'minds004_student';
$pass = 'password';
$host = 'mindspingames.com';
$db_name = 'minds004_students';
$dsn = "mysql://$user:$pass@$host/$db_name";
$db = DB::connect($dsn);
if (DB::isError($db)) {
    die ($db->getMessage());
}
if(isset($_GET['start'])): $start = $_GET['start']; else: $start = 0; endif;
$sql = "SELECT * FROM users ORDER BY id";
$result = $db->query($sql);
if (DB::isError($result)) {
    die ($result->getMessage());
}
foreach (range($start, $start + $limit - 1) as $rownum) {
    if (!$row = $result->fetchrow(DB_FETCHMODE_ASSOC, $rownum)) {
        break;
    }
    echo $row['name'] . "<BR>\n";
}
$result->free();
$numrows = $db->getOne('SELECT count(*) FROM users');
$db->disconnect();
if($start > 0) {
    echo "<a href=\"".$_SERVER['PHP_SELF']."?start=".($start - $limit)."\">Back</a><BR>\n";
}
if (($start + $limit) < $numrows) {
    echo "<a href=\"".$_SERVER['PHP_SELF']."?start=".($start + $limit)."\">Next</a><BR>\n";
}
*/

 

I'm guessing it's a problem with the database, since the code seems sound.

 

I get this error when I try the above code:

 

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in /webroot/m/i/minds004/www/test.php on line 7

Unable to select database

 

 

I just get a 'DB Error: connection failed' error when I try the commented code using pear::db.

 

I setup and account with omnis.com and setup a mysql database on their site. I don't know what's wrong, as it seems easy enough to setup. Here's a pic: omnis.JPG

 

Does anyone know what is wrong? Has anyone setup databases using omnis before?

Link to comment
https://forums.phpfreaks.com/topic/89006-solved-mysql-connecting-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.