Jump to content

MySQL server connection


matt_wood87

Recommended Posts

Hi guys,

i'm having a bit of trouble using php to interface with a mysql server, despite much searching on the web i can't find the solution to my problem so hopefully someone here might be able to help me out!

i'm pretty sure my code was working a few months back, and now it isn't without any changes. here's the problem anyway:

 

i have two files config.php and preupload.php.

when i view the page preupload.php in my browser i get the errors

 

Warning: mysql_query(): Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2) in /home/content/a/l/e/alexnail/html/website_v2/preupload.php on line 13

 

Warning: mysql_query(): A link to the server could not be established in /home/content/a/l/e/alexnail/html/website_v2/preupload.php on line 13

 

with further errors on line 14 and 19 although i think solving this would consequently solve them.

the code in preupload.php is

 

<?php
include 'config.php';

// initialization
$photo_upload_fields = '';
$counter = 1;

// If we want more fields, then use, preupload.php?number_of_fields=20
$number_of_fields = (isset($_GET['number_of_fields'])) ?
   (int)($_GET['number_of_fields']) : 5;

// Firstly Lets build the Category List
$result = mysql_query('SELECT tag_id,tag_name FROM tags');
while($row = mysql_fetch_array($result)) {
   $photo_category_list .= <<<__HTML_END
<option value="$row[0]">$row[1]</option>\n
__HTML_END;
}
mysql_free_result( $result ); 

 

with the relevant code in config.php being

 

echo "start";

$mysql_link = mysql_connect('h41mysql69.secureserver.net', 'myusername', 'mypassword');
mysql_select_db('mydatabasename') or die('Could not select database');

if (!$mysql_link) {
    die('Could not connect: ' . mysql_error());
}

echo 'Connected successfully';

 

before the errors are printed when i navigate to preupload.php i get the line 'startConnected successfullyend' printed out, so i think the connection is being made, and am at a loss to understand the error!

 

any help would be much appreciated, if you need to see any more of the code let me know!

 

thanks for your time!

 

Matt

Link to comment
https://forums.phpfreaks.com/topic/109931-mysql-server-connection/
Share on other sites

thanks for the reply's!

 

the MySQL database version is 4.1

 

and here's the rest of the code from the config.php file!

 

<?php

echo "start";

$mysql_link = mysql_connect('h41mysql69.secureserver.net', 'username', 'password');
mysql_select_db('dbname') or die('Could not select database');

if (!$mysql_link) {
    die('Could not connect: ' . mysql_error());
}

echo 'Connected successfully';

$folderName = "gallery";
$imgarray = array();
if ($handle = opendir($folderName)) {
   //echo "Directory handle: $handle\n";
   //echo "Files:\n";

   /* This is the correct way to loop over the directory. */
   while (false !== ($file = readdir($handle))) {
   //while there are files left in the folder
    $fileext = substr(strrchr($file, "."), 1);
    if(strtolower($fileext) == "jpg"){
//if the file is a jpg
//store in an array
$imgarray[0];
      //echo "<a href='$folderName/$file'>" . substr($file, 0, strlen($file)-strlen($fileext)-1) . "</a><br>";
//test
//test
//test
}
}
   closedir($handle);
}
//display all pictures in the array with a text entry box for description and order

//submit button stores all text in an array allong with filename then loop through adding to db using sql
$sql = 'INSERT INTO photos VALUES ( null, $file, /*description*/, /*order*/, /*date*/)';
  
//$sql    = 'SELECT foo FROM bar WHERE id = 42';
//$result = mysql_query($sql, $link);

//if (!$result) {
//    echo "DB Error, could not query the database\n";
//    echo 'MySQL Error: ' . mysql_error();
//    exit;
//}

//$images_dir = '/gallery';

mysql_close($mysql_link);

echo "end";

?>

 

thanks again,

 

Matt

Is the database started? =P

 

And do you have MySQL support enabled?

Go to the shell and type:

 

php -r 'ob_start(); phpinfo(); $var = strip_tags(ob_get_contents()); ob_end_clean(); echo $var;' | grep -i "mysql"

 

EDIT: If you don't have a shell (lol windows) or you can't get into it because you don't have SSH access or whatnot, then just upload a file that has <?php phpinfo(); ?> in it and look for mysql.

 

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.