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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.