Note that there are some explanatory texts on larger screens.

plurals
  1. POHow To Properly Migrate From mysql_ to PDO
    text
    copied!<p>UPDATE: This question has been answered I have a simple form where users can update their mysql db. I was using <code>mysql_</code> to connect to the database but have learned that pdo is a better way to do this since <code>mysql_</code> is depreciated.</p> <p>Included below is the complete form the OLD way followed by the complete form the new way. The new way produces an error</p> <p>OLD WAY:</p> <pre><code>&lt;?php $host = 'ip_address'; $user = 'user_name'; $password = 'password'; $link = mysql_connect($host, $user, $password); $selected = mysql_select_db('db_name', $link); if(!isset($_POST['text-input'])) ?&gt; &lt;form method="post"&gt; %slice% &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; %[if !edit]% &lt;?php %[repeat items]% $form_input%id=repeatIndex% = $_POST['element-%id=repeatIndex%'] ; %[endrepeat]% $query = 'INSERT INTO `table_name` (%[repeat items]%%[endif]%%html="Edit Me"%%[if !edit]%,%[endrepeat]%) VALUES (%[repeat items]%"' . $form_input%id=repeatIndex% . '",%[endrepeat]%);'; $query = preg_replace('/,\);/',');',$query); $query = preg_replace('/,\) /',')',$query); mysql_query($query); ?&gt; %[endif]% </code></pre> <p>The NEW Way:</p> <pre><code>&lt;?php db = new PDO('mysql:host=ip_address;dbname=db_name;', 'user_name', 'password'); ?&gt; &lt;form method="post"&gt; %slice% &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; %[if !edit]% &lt;?php %[repeat items]% $form_input%id=repeatIndex% = $_POST['element-%id=repeatIndex%'] ; %[endrepeat]% $query = 'INSERT INTO `table_name` (%[repeat items]%%[endif]%%html="Edit Me"%%[if !edit]%,%[endrepeat]%) VALUES (%[repeat items]%"' . $form_input%id=repeatIndex% . '",%[endrepeat]%);'; $query = preg_replace('/,\);/',');',$query); $query = preg_replace('/,\) /',')',$query); mysql_query($query); ?&gt; %[endif]% </code></pre> <p>The errors that gets throw is this:</p> <pre><code>Warning: mysql_query() [function.mysql-query]: Access denied for user 'kuler'@'localhost' (using password: NO) in /home/path_to/index.php on line 125 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/path_to/index.php on line 125 </code></pre> <p>I hope I have provided enough information.</p>
 

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