Jump to content

[SOLVED] not a valid MySQL-Link resource


matt_wood87

Recommended Posts

Hi Guys,

i'm having trouble using connecting to my database with php, i get an error

 

Warning: mysql_query(): 2 is not a valid MySQL-Link resource in /home/content/a/l/e/alexnail/html/website_v2/preupload.php on line 14

 

where line 14 is

 

$result = mysql_query('SELECT tag_id,tag_name FROM tags',$mysql_link)or die(mysql_error());

 

however if i try and execute the query "SELECT tag_id,tag_name FROM tags" from the mysql front end admin interface, the query runs fine and i get the correct result.

 

if anyone could offer me any solution as to why this isn't working from my code i'd be much appreciative!

 

the code from my config file:

 

$mysql_link = mysql_connect($servername, $dbusername, $dbpassword);

mysql_select_db($dbname) or die('Could not select database');

 

if (!$mysql_link) {

    die('Could not connect: ' . mysql_error());

}

 

runs fine and does not throw any errors.

 

thanks again

 

Matt

Link to comment
https://forums.phpfreaks.com/topic/110572-solved-not-a-valid-mysql-link-resource/
Share on other sites

First, please use code tags when posting. It's the button with the # sign on the toolbar.

 

Second, if you are only using 1 mysql connection, the second argument can be left off, as mysql will know which resource to use:

$result = mysql_query('SELECT tag_id,tag_name FROM tags')or die(mysql_error());

 

If that still doesn't work, please post the lines before line 14

thanks for the reply!

 

i made the change, and i get the print out

 

startConnected successfullyDirectory handle: Resource id #3 Files: end

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 14

 

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 14

Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2)

 

pre 14 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')or die(mysql_error());

 

and config.php is

 

<?php

echo "start";

$servername = 'h41mysql69.secureserver.net';
$dbusername = '***username***';
$dbpassword = '***password***';
$dbname = '***dbname***';

$mysql_link = mysql_connect($servername, $dbusername, $dbpassword);
mysql_select_db($dbname) or die('Could not select database');

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

echo 'Connected successfully';

$folderName = "gallery/full_res";
$imgarray = array();
if ($handle = opendir($folderName)) {
    echo "Directory handle: $handle\n";
    echo "Files:\n";
    
    $loopi=0;
    /* 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"){
    $imgarray[$loopi] = $folderName.'/'.$file;
    $loopi++;
}
    }
    closedir($handle);
}

mysql_close($mysql_link);

echo "end";

?>

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.