SQL Error I've Not Previously Encountered

Problems with the Windows version of XAMPP, questions, comments, and anything related.

SQL Error I've Not Previously Encountered

Postby KallistaAEnvarou » 23. March 2008 06:26

I keep getting "Can't connect to MySQL server on 'localhost' (10048)" when I try to run my scripts. Also, phpMyAdmin keeps telling me the server is not responding. What does all this mean? I've tried restarting XAMPP, but that didn't help. The Apache error log doesn't give me any errors. What do I do to fix this problem?
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

Postby Wiedmann » 23. March 2008 06:33

Your MySQL server is running?
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby KallistaAEnvarou » 23. March 2008 08:07

I think so. I restarted the computer and ran xampp_start.exe. I was running a script earlier, and it was (sort of) working, but then all of a sudden I got that error. I say sort of because I was getting a semi-infinity loop. I'm trying to create a cookie-setting function that creates a unique key for each new user, and it was setting like 10 times. Here is my code.

User-Definied Function Definitions
Code: Select all
function cgkey(&$cgkey)
{
   /**
   Function Statement:   Generates a computer-generated key 36 characters long
   1.   Input
      $cgkey
         passed to function for return by reference
         denotes computer-generated key function will return
   2.   Proccess
      empty $cgkey just in case it was set before being passed to function
      set $pattern to be all alphanumeric characters
      Loop [for $p=0;$p < 36;$p++]
         choose one of the letters and add to the end of $cgkey
      End Loop
   3.   Output
      pass $cgkey by reference
   */
   $cgkey="";
   $pattern='abcdefghijklmnopqrstuvwxyz1234567890';
   for($p=0;$p<36;$p++)
   {
      $cgkey.=$pattern{rand(0,35)};
   }
}

function closesql($line)
{
   /**
   Function Statement: closes the mysql connecton
   1.   Input
      none
   2.   Process
      close connection linked to $GLOBALS['con']
   3.   Output
      None
   */
   global $file;
   mysql_close($GLOBALS['con']) or die("Could not close connection on line $line in $file." . mysql_error());
}

function opensql($user,$db,$line)
{
   /**
   Function Statement: connects to the database using one line of code
   1.   Input
      $username
         passed to function
         denotes username to conect
      $db
         passed to function
         denotes database to connect to
      $line
         passed to function via __LINE__ constant
         denotes line number of any possible error
      $file
         grabbed via global keyword
         denotes file name where any possible error may have occurred
   2.   Process
         global $file //grabs $file variable
         use $GLOBALS variable to set $con to connect to the server with the given user. quit and error on failure.
         use $GLOBALS variable to set $db to select the database witht he given user. quit and error on failure.
   */
   global $file;
   $GLOBALS['con']=@mysql_connect("localhost","phplearn_$user","Char1133") or die("Could not connect $user to server on line $line in $file: ".mysql_error());
   $GLOBALS['db']=@mysql_select_db("phplearn_reportingscience_$db") or die("Could not connect $user to $db on line $line in $file: ".mysql_error());
}

function sql($query,$line)
{
   /**
   Function Statement:   Uses one line of code to perform an SQL query
   1.   Input
      $query
         passed to function
         denotes query to process
      $line
         passed to function
         denotes line number of failure if there is one
      $file
         grabbed from global scope via global keyword
         denotes the file name of failure if there is one
   2.   Process
      global $file //grabs $file from global scope
      process query. quit on failure with a message saying the location. store result to $result
   3.   Output
      reutrn $result
   */
   global $file;
   $result=mysql_query($query) or die("Query on $line in $file failed: " . mysql_error());
   return $result;
}

function sqlrows(&$rows,$query,$line)
{
   /**
   Function Statement: determines the number of rows a given query has. exits and errors on failure
   1.   Input
      $rows
         passed to function for return by reference
         number of rows that the query matches
      $query
         passed to function
         denotes the query to be run
      $line
         passed to function via __LINE__ constant
         denotes the line of any error.
      $file
         grabbed from global scope via global keyword
         denotes the file that called this function
   2.   Process
      global $file;
      run sql function and store to $result //function definiton above
      find the number of rows and store to $rows
   3.   Output
      pass $rows by reference
   */
   global $file;
   $result=sql($query,$line . '(sql function)');
   $rows=mysql_num_rows($result);
}


Code executing the functions
Code: Select all
if($cookievalue)
{
   opensql('s','users',__LINE__);
   sqlrows($validid,"SELECT * FROM cookieinfo WHERE cookievalue='$key' AND browser='{$_SERVER['HTTP_USER_AGENT']}' AND ip='{$_SERVER['REMOTE_ADDR']}'",__LINE__);
   if(!$validid)
   {
      setcookie('sessid','',1);
      header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
   }
   closesql(__LINE__);
}

while(!$_COOKIE['sessid'])
{
   cgkey($key);
   opensql('s','users',__LINE__);
   sqlrows($isused,"SELECT * FROM cookieinfo WHERE cookievalue='$key'",__LINE__);
   closesql(__LINE__);
   if(!$isused)
   {
      opensql('i','users',__LINE__);
      sql("INSERT INTO cookieinfo VALUES('A','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['HTTP_USER_AGENT']}','')",__LINE__);
      closesql(__LINE__);
      setcookie('sessid','$key',time()+365.25*24*60*60);
      header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
   }
}
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

Postby Wiedmann » 23. March 2008 15:26

I think so.

You can see mysqld.exe in the Windows task manager?
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby KallistaAEnvarou » 23. March 2008 23:59

No, but I never have. I only run xampp_start.exe, and it says that both Apache and MySql are running. I've tried everything I can think of, even clearing my cache, except reinstall XAMPP, and I have no clue what to do.
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

Postby Wiedmann » 24. March 2008 00:18

No

You can't see mysqld.exe in the Windows task manager? In this case MySQL is not running.

Start MySQL with the batch file and read the (error-) message.
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby KallistaAEnvarou » 24. March 2008 00:22

It's never been in my start tray before, but this thing always pops up.

Image
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

Postby Wiedmann » 24. March 2008 01:27

with the batch file

A batchfile have the extension "*.bat". In this case "mysql_start.bat". (and not "xampp_start.exe").
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby KallistaAEnvarou » 24. March 2008 01:36

Oh wait, task manager. Not start menu tray.

Silly me. Yes, it's there.

Edit: OK, I upgraded to 1.6.6a. The problem seems to be fixed now. Thanks though.
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California


Return to XAMPP for Windows

Who is online

Users browsing this forum: Altrea and 69 guests