matt_wood87 Posted June 12, 2008 Share Posted June 12, 2008 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 More sharing options...
jonsjava Posted June 12, 2008 Share Posted June 12, 2008 your errors are common in 2 situations: 1: you upgraded to PHP5 and didn't install the libraries to handle MySQL connections 2: Your MySQL server is down/unreachable for some reason. Let us know if either of those are possible. Link to comment https://forums.phpfreaks.com/topic/109931-mysql-server-connection/#findComment-564110 Share on other sites More sharing options...
conker87 Posted June 12, 2008 Share Posted June 12, 2008 Can we see the entire config.php? And in [ php ] [ /php ] tags too Or indeed, you have php5. Stupid not integrating MySQL! Link to comment https://forums.phpfreaks.com/topic/109931-mysql-server-connection/#findComment-564111 Share on other sites More sharing options...
matt_wood87 Posted June 13, 2008 Author Share Posted June 13, 2008 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 Link to comment https://forums.phpfreaks.com/topic/109931-mysql-server-connection/#findComment-564463 Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 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. Link to comment https://forums.phpfreaks.com/topic/109931-mysql-server-connection/#findComment-564471 Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 Never mind. You obviously have MySQL installed, otherwise you'd get "Undefined function mysql_query()" as an error, not those. Make sure the server is running. Link to comment https://forums.phpfreaks.com/topic/109931-mysql-server-connection/#findComment-564472 Share on other sites More sharing options...
matt_wood87 Posted June 13, 2008 Author Share Posted June 13, 2008 the server is running because i can access my website which is on the same server, and it has to be running for me to get the errors in the first place, or the page wouldn't load! Link to comment https://forums.phpfreaks.com/topic/109931-mysql-server-connection/#findComment-564671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.