<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — mysqli usage]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=4525&amp;type=atom" />
	<updated>2015-03-04T16:03:53Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=4525</id>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22781#p22781" />
			<content type="html"><![CDATA[<p>Try replacing `mysql_real_escape_string` by `db_escape` in includes/db_pager.inc.</p>]]></content>
			<author>
				<name><![CDATA[elax]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=6206</uri>
			</author>
			<updated>2015-03-04T16:03:53Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22781#p22781</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=21294#p21294" />
			<content type="html"><![CDATA[<p>but please help , u can see above update thats</p><p>and if i click on sorting asc or desc then</p><p>&quot;//-----</p><p>DATABASE ERROR : Error browsing database: SELECT id,name,datetime FROM &quot;.TB_PREF.&quot;test_table&nbsp; &nbsp;ORDER BY ,&nbsp; LIMIT 0, 10<br />error code : 1064<br />error message : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;LIMIT 0, 10&#039; at line 1<br />sql that failed was : SELECT id,name,datetime FROM &quot;.TB_PREF.&quot;test_table ORDER BY LIMIT 0, 10</p><p>---//&quot;</p><br /><br /><p>see <strong> ORDER BY ,&nbsp; </strong></p><p>i think field name is not coming here ...</p><p>as the i have already shifted from MYSQL TO MYSQLI as per above code ... but only sorting is not working... it would be great if u look in it pls..</p><p>also by when 2.4 will be out ... else i would be to rework on many pages ...</p><p>pls help</p>]]></content>
			<author>
				<name><![CDATA[tester1]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18290</uri>
			</author>
			<updated>2014-11-01T12:18:57Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=21294#p21294</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=21293#p21293" />
			<content type="html"><![CDATA[<p>We have implemented the mysqli driver routines in release 2.4. We do not have the resources to discuss ev. Mysqli routines during release 2.3.</p><p>When we are shipping the 2.4 we can take those discussions again.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2014-11-01T11:50:09Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=21293#p21293</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=21291#p21291" />
			<content type="html"><![CDATA[<p>Hi,</p><p>After using above Mysqli my table sorting by asc/desc&nbsp; is not working </p><p>which is because of </p><div class="codebox"><pre><code>function db_field_name($result, $n)
{
    //return mysql_field_name($result, $n);
    $fieldinfo = mysqli_fetch_field_direct($result, $n);
    return $fieldinfo-&gt;name;
    
    
}</code></pre></div><p>getting error:</p><p>&quot;//-----</p><p>DATABASE ERROR : Error browsing database: SELECT id,name,datetime FROM &quot;.TB_PREF.&quot;test_table&nbsp; ORDER BY LIMIT 0, 10<br />error code : 1064<br />error message : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;LIMIT 0, 10&#039; at line 1<br />sql that failed was : SELECT id,name,datetime FROM &quot;.TB_PREF.&quot;test_table ORDER BY LIMIT 0, 10</p><p>---//&quot;</p><p>and if i click on sorting asc or desc then</p><p>&quot;//-----</p><p>DATABASE ERROR : Error browsing database: SELECT id,name,datetime FROM &quot;.TB_PREF.&quot;test_table&nbsp; &nbsp;ORDER BY ,&nbsp; LIMIT 0, 10<br />error code : 1064<br />error message : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;LIMIT 0, 10&#039; at line 1<br />sql that failed was : SELECT id,name,datetime FROM &quot;.TB_PREF.&quot;test_table ORDER BY LIMIT 0, 10</p><p>---//&quot;</p><br /><br /><p>see <strong> ORDER BY ,&nbsp; </strong></p><p>i think field name is not coming here ...<br />chk : https://frontaccounting.com/punbb/viewtopic.php?pid=21292</p><br /><br /><p>i had also post the query here :&nbsp; https://frontaccounting.com/punbb/viewtopic.php?id=4967</p><p>and after long time i found the prb .. i dont know its in that function or not but when i replace all mysql to mysqli as per above code my asc desc stop working .. any idea ???</p>]]></content>
			<author>
				<name><![CDATA[tester1]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18290</uri>
			</author>
			<updated>2014-11-01T11:19:18Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=21291#p21291</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=19851#p19851" />
			<content type="html"><![CDATA[<p>We have now implemented driver for mysqli in the 2.4 environment, althoug not ready yet.</p><p>We are still testing this. During testing we found some bad SQL statements in the core, although they went fine under the mysql driver. These errors are fixed and surely more to come during testing.</p><p>Will be committed to 2.4 unstabe as soon as we have tested it.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2014-05-05T14:46:03Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=19851#p19851</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=19223#p19223" />
			<content type="html"><![CDATA[<p>I dont see what&#039;s wrong, your data are stored normally with no loss and you&#039;re able to follow all transactions correctly.<br />if you really need to manage begin, commit and rollback here&#039;s a beginning of the answer:</p><p>http://stackoverflow.com/questions/9584833/mysql-autoincrement-value-jumps-by-2-when-i-add-a-transcaction-im-my-php-code</p><p>check the last answer.</p>]]></content>
			<author>
				<name><![CDATA[ostertagi]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18743</uri>
			</author>
			<updated>2014-02-07T10:01:50Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=19223#p19223</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=19218#p19218" />
			<content type="html"><![CDATA[<p>@ ostertagi , Dude i also shifted from MYSQL -&gt; MYSQLI </p><p>But did u saw <strong> cancel_transaction(); </strong> thats Transactions </p><p>as we are using MySqli&nbsp; hence in mysqli there&nbsp; is default</p><p><strong> mysqli_rollback and mysqli_commit&nbsp; ...etc Transactions </strong> </p><p>Hence do we need to work out under includes/db/sql_functions.inc&nbsp; for same ? ..</p><p>Please let me know ... also How an we try this as TRY {} CATCH {} ... which i have asked under : https://frontaccounting.com/punbb/viewtopic.php?id=4726</p>]]></content>
			<author>
				<name><![CDATA[tester1]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18290</uri>
			</author>
			<updated>2014-02-07T07:26:21Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=19218#p19218</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18604#p18604" />
			<content type="html"><![CDATA[<p>yes, I will be happy if we can go with PDO. I hope PDO will be implemented in next release, or next big release.</p><p>for now, my urgent need is to minimize deprecated function so we can safely follow the mysql update.</p>]]></content>
			<author>
				<name><![CDATA[mfaa98]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17843</uri>
			</author>
			<updated>2013-11-29T03:58:06Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18604#p18604</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18558#p18558" />
			<content type="html"><![CDATA[<p>Obviously pdo wins. but since, i&#039;m a java developer it&#039;s hard for me to talk about poo while there is no item class, account class and so on.<br />if i was to implement an orm in FA, i would certainly rewrite all xxxxx_db.inc and use a lot of pojo-like object to handle data in a more appropriate way.<br />i dont know if this is relevant in php (i&#039;m still a newbie: couple of mounths since i&#039;ve started php), but until there is a significant upgrade to FA core, using mysqli is just fine by me.<br />here is the last update to my connect_db.inc (with no DB_escape_string() this time):<br /></p><div class="codebox"><pre><code>&lt;?php

/*
 * using mysqli_connect instead of mysql_connect
 */

function set_global_connection($company = -1) {
    global $db, $transaction_level, $db_connections;

    cancel_transaction();
    // cancel all aborted transactions if any
    $transaction_level = 0;

    if ($company == -1) {
        $company = $_SESSION[&quot;wa_current_user&quot;]-&gt;company;
    }

    $_SESSION[&quot;wa_current_user&quot;]-&gt;cur_con = $company;

    $connection = $db_connections[$company];
    $db = mysqli_connect($connection[&quot;host&quot;], $connection[&quot;dbuser&quot;], $connection[&quot;dbpassword&quot;]);
    mysqli_select_db($db, $connection[&quot;dbname&quot;]);
    return $db;
}

$db_duplicate_error_code = 1062;

//DB wrapper functions to change only once for whole application

function db_query($sql, $err_msg = null) {
    global $db, $show_sql, $sql_trail, $select_trail, $go_debug, $sql_queries, $Ajax, $db_connections, $db_last_inserted_id;

    // set current db prefix
    $cur_prefix = $db_connections[$_SESSION[&quot;wa_current_user&quot;]-&gt;cur_con][&#039;tbpref&#039;];
    $sql = str_replace(TB_PREF, $cur_prefix, $sql);

    if ($show_sql) {
        $Ajax-&gt;activate(&#039;footer_debug&#039;);
        $sql_queries .= &quot;&lt;pre&gt;$sql&lt;/pre&gt;\n&lt;hr&gt;&quot;;
    }

    $result = mysqli_query($db, $sql);

    if ($sql_trail) {
        $db_last_inserted_id = mysqli_insert_id($db);
        // preserve in case trail insert is done
        if ($select_trail || (strstr($sql, &#039;SELECT&#039;) === false)) {
            mysqli_query($db, &quot;INSERT INTO &quot; . $cur_prefix . &quot;sql_trail
                (`sql`, `result`, `msg`)
                VALUES(&quot; . db_escape($sql) . &quot;,&quot; . ($result ? 1 : 0) . &quot;,
                &quot; . db_escape($err_msg) . &quot;)&quot;);
        }
    }

    if ($err_msg != null || $go_debug) {
        $exit = $err_msg != null;
        if (function_exists(&#039;xdebug_call_file&#039;))
            check_db_error(&#039;&lt;br&gt;At file &#039; . xdebug_call_file() . &#039;:&#039; . xdebug_call_line() . &#039;:&lt;br&gt;&#039; . $err_msg, $sql, $exit);
        else
            check_db_error($err_msg, $sql, $exit);
    }
    return $result;
}

function db_fetch_row($result) {
    return mysqli_fetch_row($result);
}

function db_fetch_assoc($result) {
    return mysqli_fetch_assoc($result);
}

function db_fetch($result) {
    return mysqli_fetch_array($result);
}

function db_seek(&amp;$result, $record) {
    return mysqli_data_seek($result, $record);
}

function db_free_result($result) {
    if ($result) {
        mysqli_free_result($result);
    }
}

function db_num_rows($result) {
    return mysqli_num_rows($result);
}

function db_num_fields($result) {
    return mysqli_num_fields($result);
}

function db_escape($value = &quot;&quot;, $nullify = false) {
    global $db;
    $value = @html_entity_decode($value, ENT_QUOTES, $_SESSION[&#039;language&#039;]-&gt;encoding);
    $value = @htmlspecialchars($value, ENT_QUOTES, $_SESSION[&#039;language&#039;]-&gt;encoding);

    //reset default if second parameter is skipped
    $nullify = ($nullify === null) ? (false) : ($nullify);

    //check for null/unset/empty strings
    if ((!isset($value)) || (is_null($value)) || ($value === &quot;&quot;)) {
        $value = ($nullify) ? (&quot;NULL&quot;) : (&quot;&#039;&#039;&quot;);
    } else {
        if (is_string($value)) {

            $value = &quot;&#039;&quot; . mysqli_real_escape_string($db, $value) . &quot;&#039;&quot;;
        } else if (!is_numeric($value)) {
            //value is not a string nor numeric
            display_error(&quot;ERROR: incorrect data type send to sql query&quot;);
            echo &#039;&lt;br&gt;&lt;br&gt;&#039;;
            exit();
        }
    }
    return $value;
}

function db_error_no() {
    return mysqli_connect_errno();
}

function db_error_msg($db) {
    return mysqli_error($db);
}

function db_insert_id() {
    global $db_last_inserted_id, $sql_trail, $db;
    return $sql_trail ? $db_last_inserted_id : mysqli_insert_id($db);
}

function db_num_affected_rows() {
    global $db;
    return mysqli_affected_rows($db);
}

function db_field_name($result, $n) {
    //return mysqli_field_name($result, $n);
    $fieldinfo = mysqli_fetch_field_direct($result, $n);
    return $fieldinfo-&gt;name;
}

function db_create_db($connection) {
    $db = mysqli_connect($connection[&quot;host&quot;], $connection[&quot;dbuser&quot;], $connection[&quot;dbpassword&quot;]);
    if (!mysqli_select_db($db, $connection[&quot;dbname&quot;])) {
        $sql = &quot;CREATE DATABASE IF NOT EXISTS &quot; . $connection[&quot;dbname&quot;] . &quot;&quot;;
        if (!mysqli_query($db, $sql) || !mysqli_select_db($db, $connection[&quot;dbname&quot;])) {
            return 0;
        }
    }
    return $db;
}

function db_drop_db($connection) {

    if ($connection[&quot;tbpref&quot;] == &quot;&quot;) {
        $sql = &quot;DROP DATABASE IF EXISTS &quot; . $connection[&quot;dbname&quot;] . &quot;&quot;;
        return mysqli_query($db, $sql);
    } else {
        $res = db_query(&quot;show table status&quot;);
        $all_tables = array();
        while ($row = db_fetch($res)) {
            $all_tables[] = $row;
        }
        // get table structures
        foreach ($all_tables as $table) {
            if (strpos($table[&#039;Name&#039;], $connection[&quot;tbpref&quot;]) === 0) {
                db_query(&quot;DROP TABLE `&quot; . $table[&#039;Name&#039;] . &quot;`&quot;);
            }
        }
        //deleting the tables, how??
        return true;
    }
}

function db_close($dbase = null) {
    global $db;

    if (!$dbase) {
        $dbase = $db;
    }
    return mysqli_close($dbase);
}

?&gt;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[ostertagi]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18743</uri>
			</author>
			<updated>2013-11-25T21:04:33Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18558#p18558</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18549#p18549" />
			<content type="html"><![CDATA[<p><a href="http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/">MySQLi vs. PDO_mysql</a></p><p>Any reason for capitalising the DB in DB_escape_string() function name?</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2013-11-24T21:13:41Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18549#p18549</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18548#p18548" />
			<content type="html"><![CDATA[<p>i was experiencing some bug while saving non utf8 strings, after some tests i modified the DB_escape_string :</p><div class="codebox"><pre><code> 
function DB_escape_string($String) {
    global $db;
//    return mysqli_real_escape_string($db, htmlspecialchars($String, ENT_COMPAT, &#039;utf-8&#039;, false));
    return mysqli_real_escape_string($db, $String);
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[ostertagi]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18743</uri>
			</author>
			<updated>2013-11-24T14:41:16Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18548#p18548</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18456#p18456" />
			<content type="html"><![CDATA[<p>ostertagi@yahoo.fr</p>]]></content>
			<author>
				<name><![CDATA[ostertagi]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18743</uri>
			</author>
			<updated>2013-11-15T13:22:48Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18456#p18456</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18454#p18454" />
			<content type="html"><![CDATA[<p>@ ostertagi</p><p>god promise this was my new post for today with Question &quot; Does FA Support Mysqli and Postgresql &quot; and guess what i found my answer on First Post of it.. </p><p>Gr8 work dude ,&nbsp; u r right Weberp provide many Db Ext.&nbsp; let see may be new few next version of FA we can see all Ext. <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>thanks onceagain also can you please let me know u r email id .. as i need some more help from u&nbsp; r side <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[tester1]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18290</uri>
			</author>
			<updated>2013-11-15T12:38:57Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18454#p18454</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18448#p18448" />
			<content type="html"><![CDATA[<p>thanx, i missed this one!!</p>]]></content>
			<author>
				<name><![CDATA[ostertagi]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18743</uri>
			</author>
			<updated>2013-11-14T09:27:25Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18448#p18448</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: mysqli usage]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18443#p18443" />
			<content type="html"><![CDATA[<p>@ostertagi, <br />Thank you for your work. I really need it.<br />To be honest, I am wondering too since it might not that difficult to do simple update to newer technology. <br />But i do understand that some core update like database connection means another thorough test.<br />I will report here if there still another problem.</p><p>here is update for certain function. I have tested this function: <br /></p><div class="codebox"><pre><code>function db_field_name($result, $n) {
    //return mysqli_field_name($result, $n);
    $fieldinfo = mysqli_fetch_field_direct($result, $n);
    return $fieldinfo-&gt;name;
}</code></pre></div><p><a href="http://us1.php.net/manual/en/mysqli-result.fetch-field-direct.php">source</a></p>]]></content>
			<author>
				<name><![CDATA[mfaa98]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17843</uri>
			</author>
			<updated>2013-11-14T00:26:19Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18443#p18443</id>
		</entry>
</feed>
