PHP connecting to DB : OOP vs Procedural 1 dont work 2 works
<p>I am scratching my empty head with this issue:</p>

<p>When I have my logging data as procedural, everything works fine. I require the file once and can proceed with my select queries. If the connection to the DB file is however written as OOP. I get the error that No database selected</p>

<p>====</p>

<pre><code>&lt;?php

        // SETTING VALUES AS CONSTANTS

        DEFINE('DB_USER', 'root');
        DEFINE('DB_PASSWORD', '');
        DEFINE('DB_HOST', 'localhost');
        DEFINE('DB_NAME', 'tra');

        // CONNECTING JUST TO THE SERVER
        $dbc = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

        if (!$dbc)  // IF IT CAN'T CONNECT, ISSUE A MESSAGE
             {
                die('Could not connect: ' . mysql_error());
        }

        // CONNECTING NOW TO THE DB
        mysql_select_db("tra", $dbc);

    ?&gt;
</code></pre>

<p>So that up there works fine. I have got that in a separate file, (out of the root path)</p>

<p>But if I try to do it OOP, then, the rest of the queries that are to work once I have the access to the DB won't work. I sometimes get the query written as output, I mean as if not executing, just the plain text:</p>

<pre><code>   $mysqli = new mysqli("localhost", "root", "");
            $mysqli-&gt;select_db("tra");
</code></pre>

<p>I have tried tons of varieties with the OOP version, first instantiating separately such as </p>

<pre><code>$mysqli = new mysli();
$mysqli-&gt;connect("127.0.0.1", "root", "", "tra");
</code></pre>

<p>or also </p>

<pre><code>$mysqli = new mysqli("localhost", "root", "");
$mysqli-&gt; select_db("tra");
</code></pre>

<p>but none of the tries with OOP will work. I mean, I have the book on my lap, so I am writing it ad litteram. The issue must be elsewhere.</p>

<p>The PHP version is 5.3.8 about the latest one. </p>

<p>The sql query that follows after the connection and selection of the DB (which works if the connection file is procedural, as I say) is:</p>

<pre><code>$sql ="SELECT FName
                              FROM work_assignment, developer
                              WHERE developer.country = '".$country."'
                              AND work_assignment.from_language = '".$from."'
                              AND work_assignment.into_language = '".$into."'
                              AND work_assignment.developer_id = developer.developer_id

                              ";
</code></pre>

<p>Any ideas as to why?</p>

<p>Thanks a lot</p>
