Hi all,
I have written a few usertags which needs access to the database of CMSMS. Up to PHP 5.5 I could easily use
mysql_query("TRUNCATE TABLE `buffertime`");
which works fine. With PHP 7 I need a second parameter:
mysqli_query($link,"TRUNCATE TABLE `buffertime`");
What is a correct, predefined variablename for $link containing the current database?
As a workaround I wrote a function open_db(), which will do the job using mysqli_connect and set $link = open_db().
But that cannot be the solution to the problem. Any hint?
Thanks in advance!
Regards Peter
DB access inside a usertag with PHP 7
DB access inside a usertag with PHP 7
Regards from Germany, Peter
Re: DB access inside a usertag with PHP 7
this works for me (on php 5.6.x or 7.0.x)
to access another database (not cmsms) to access cmsms i think this is all that's needed: and then run your query: you may need to reconnect to cmsms with
to access another database (not cmsms)
Code: Select all
$db = NewADOConnection('mysqli');
//assuming those $db_ vars are defined:
$db->Connect($db_host,$db_user,$db_pw,$db_db);
Code: Select all
$db = cmsms()->GetDb;
Code: Select all
$query = "SELECT * FROM sometable";
$dbr = $db->Execute($query);
while( $dbr && !$dbr->EOF ) {
print_r($dbr->fields);
$dbr->MoveNext();
}
Code: Select all
adodb_connect();
Re: DB access inside a usertag with PHP 7
It's not difficult to do that. $link means only connection ID.
You can get for current db with
, so this will work
You can get for current db with
Code: Select all
$db = cmsms()->GetDb();
$dbid = $db->connectionId;
Code: Select all
$result = mysqli_query($dbid , 'select * from cms_content;');
Re: DB access inside a usertag with PHP 7
Hi chandra,
thanks, that is exactly, what I was searching for! It works great.
thanks, that is exactly, what I was searching for! It works great.
Regards from Germany, Peter