Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you connect to the database like this :</p> <pre><code>$dbhost = "localhost"; $dbname = "testcreate"; $dbuser = "root"; $dbpass = "mysql"; try { $db = new PDO('mysql:host='.$dbhost.';dbname='.$dbname.';charset=utf-8', ''.$dbuser.'', ''.$dbpass.''); $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo 'Error : &lt;br&gt;' . $e-&gt;getMessage(); } </code></pre> <blockquote> <p><strong>PS: You dont need the try and the catch, but we used to get the error and handle it in a nice way as we want to</strong></p> </blockquote> <p>and next we query like this :</p> <pre><code> $db-&gt;query(SELECT * FROM node WHERE node_name='$nodename'"); </code></pre> <p>and we fetch it like this :</p> <pre><code> $query = $db-&gt;query(SELECT * FROM node WHERE node_name='$nodename'"); $row = $query-&gt;fetch(PDO::FETCH_OBJ); </code></pre> <p>and now you use <code>$row-&gt;name</code> for example </p> <p>here is more about PDO::FETCH</p> <blockquote> <ul> <li><p><strong>PDO::FETCH_ASSOC</strong>: returns an array indexed by column name as returned in your result set</p></li> <li><p><strong>PDO::FETCH_BOTH</strong> (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set</p></li> <li><p><strong>PDO::FETCH_BOUND</strong>: returns TRUE and assigns the values of the columns in your result set to the PHP variables to which they were<br> bound with the PDOStatement::bindColumn() method</p></li> <li><p><strong>PDO::FETCH_CLASS</strong>: returns a new instance of the requested class, mapping the columns of the result set to named properties in the<br> class. If fetch_style includes PDO::FETCH_CLASSTYPE (e.g.<br> <strong>PDO::FETCH_CLASS</strong> | <strong>PDO::FETCH_CLASSTYPE)</strong> then the name of the class<br> is determined from a value of the first column.</p></li> <li><p><strong>PDO::FETCH_INTO</strong>: updates an existing instance of the requested class, mapping the columns of the result set to named properties in<br> the class</p></li> <li><p><strong>PDO::FETCH_LAZY</strong>: combines PDO::FETCH_BOTH and PDO::FETCH_OBJ, creating the object variable names as they are accessed</p></li> <li><p><strong>PDO::FETCH_NUM</strong>: returns an array indexed by column number as returned in your result set, starting at column 0</p></li> <li><p><strong>PDO::FETCH_OBJ</strong>: returns an anonymous object with property names that correspond to the column names returned in your result set</p></li> </ul> </blockquote>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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