Uutiset:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu
Advertisement:

Problem with SSI.php - No database selected

Aloittaja Jineps, helmikuu 28, 2014, 11:01:29 AP

« edellinen - seuraava »

Jineps

Lainaus käyttäjältä: Havenworld - heinäkuu 12, 2009, 09:15:49 AP
I'm having a similar problem, the "No database selected" error. It is returned every time my PHP scripts try to execute any basic query.


global $scripturl, $db_connection, $db_passwd, $maintenance, $db_server, $options;
global $db_name, $db_user, $db_prefix, $db_persist, $db_error_send, $db_last_error, $sc, $context;
global $settings, $sourcedir;
require("../forums.havenworld.co.uk/SSI.php");


All the ssi functions work with that in my websites config file, but whenever I execute a NORMAL MySQL query using the default PHP functions I get the "No database selected" error.


I have too like this problem, anybody can help me ? same database but some tables havent got smf_ prefix.
SSI.php
No database selected

margarett

Please don't hijack such an old topic, especially already marked as solved. I'm splitting this (and replying shortly)

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

margarett

If you don't have the prefix, you need to build the table information yourself. Something like this:



<?php
// Include the SSI file.
require(dirname(__FILE__) . '/SSI.php');
global 
$db_name$smcFunc;

$my_prefix '`' $db_name '`.';

.................

//Before your query:
$table $my_prefix 'table_name';

//The query, finally...
$result $smcFunc['db_query']('''
SELECT something
FROM ' 
$table '
WHERE conditions'
);
....
$smcFunc['db_free_result'] ($result);
?>

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Jineps


@margarett thank you its worked.But why I cant use simple query like $query = mysql_query("Select * bla bla bla"); can i use like this ?

margarett

For one, that's a deprecated function in latest PHP versions. In your custom PHP code you should be able to use it, but inside SMF it is blocked for security and cross-database operation.

Quoting Arantor: :P
Lainaa
The Book of Arantor, 17:3-5
  And I said unto him, thy database query shalt always be sent by the messenger of $smcFunc
  And $smcFunc shall protect you against injections and evil
  And so it came to pass that mysql_query was declared deprecated and even though he says he is not dead yet, the time was soon to come to pass when mysql_query shall be gone and no more
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Jineps

Thank you @margarett, I'm changing all queries now.

I found all of queries :)

http://wiki.simplemachines.org/smf/$smcFunc


margarett

Great ;)

I'm now marking this as solved, feel free to undo it if you need further help.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Advertisement: