Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing same session ID in ajax can't connect to MySQL DB
    primarykey
    data
    text
    <p>I have made a generic PHP script to use for an AJAX call. I have the username and password for the mysql connection stored in SESSION variables. In order to start the same session in this ajax script, I pass the session ID via post to the ajax script. The variables are being passed correctly and I checked using <code>error_log</code> that the username and password SESSION variables are the correct values. Here is the ajax_script.php:</p> <pre><code>&lt;?php session_id($_POST['session_id']); session_start(); mysql_connect('10.X.X.X',$_SESSION['username'],$_SESSION['password']); $results = mysql_query($_POST['query']); echo json_encode($results); ?&gt; </code></pre> <p>However, the connection cannot be established. I checked the log file and this is the error:</p> <pre><code> PHP Warning: mysql_connect(): Access denied for user 'username'@'25.1.1.1' (using password: YES) in /ajax_script.php on line 6, referer: http://25.1.1.1/index.php?option=com_content&amp;view=article&amp;id=180 </code></pre> <p>Does anyone know why I cannot connect like this?</p> <p>Previously I made a similar script, but did NOT start the same session referencing the session_id like above. I passed user names and passwords via post, and the connection worked. </p> <p>Thanks!</p> <p>** EDIT ** Sorry, I used the wrong IP for the mysql connection. the following code works:</p> <pre><code>&lt;?php session_start(); $ajax_connection = mysql_connect('10.X.X.X',$_SESSION['username'],$_SESSION['password']); $result_set = array(); while ($result_set[] = mysql_fetch_assoc($results)){ // do nothing } echo json_encode($results); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload