![]() |
Connecting to multiple databases ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Connecting to multiple databases ? (/showthread.php?tid=42434) |
Connecting to multiple databases ? - El Forum - 06-07-2011 [eluser]spaquet[/eluser] I read many posts on this forum but for now it does not seem to be working at all... My application uses an ERP as backend and offer to some users a easy way to get data from it and track some of their activity on the side of this ERP, reason why there is a second database (to manange CI_Session, user activity and some requests that are not part of the ERP). What I've done: I added a second database in database.php (sugarcrm) and have the following code for my user controller : Code: Class User_model extends CI_Model { I made sure the database user connect to the database and that the query is valid (I tested in on the database). Now when calling alidates_user_from_erp from my login controller Code: public function validate_credentials() { I have the following error message : Quote:Trying to get property of non-objectrefering to the line Quote:$query->num_rows == 1of my User model. It looks like the $query object is not a database object as expected and thus I can not use database methods on it. Any help is welcome as I have the feeling I've done what I read in CI User Guide and several posts from this forum. Connecting to multiple databases ? - El Forum - 06-07-2011 [eluser]InsiteFX[/eluser] Maybe because your calling num_rows wrong! Code: // wrong! InsiteFX Connecting to multiple databases ? - El Forum - 06-07-2011 [eluser]spaquet[/eluser] Now I have the following message: Quote:PHP Fatal error: Call to a member function num_rows() on a non-object in user_model.php on line 24 Connecting to multiple databases ? - El Forum - 06-07-2011 [eluser]InsiteFX[/eluser] Well non-object meaqns it is not seeing the database! I would verify that the database is being set. Code: function __construct() { InsiteFX Connecting to multiple databases ? - El Forum - 06-07-2011 [eluser]spaquet[/eluser] Looks like it is connected, here is the dump: Quote:object(CI_DB_mysqli_driver)#22 (70) { ["dbdriver"]=> string(6) "mysqli" ["_escape_char"]=> string(1) "`" ["_like_escape_str"]=> string(0) "" ["_like_escape_chr"]=> string(0) "" ["_count_string"]=> string(19) "SELECT COUNT(*) AS " ["_random_keyword"]=> string(7) " RAND()" ["delete_hack"]=> bool(true) ["ar_select"]=> array(0) { } ["ar_distinct"]=> bool(false) ["ar_from"]=> array(0) { } ["ar_join"]=> array(0) { } ["ar_where"]=> array(0) { } ["ar_like"]=> array(0) { } ["ar_groupby"]=> array(0) { } ["ar_having"]=> array(0) { } ["ar_keys"]=> array(0) { } ["ar_limit"]=> bool(false) ["ar_offset"]=> bool(false) ["ar_order"]=> bool(false) ["ar_orderby"]=> array(0) { } ["ar_set"]=> array(0) { } ["ar_wherein"]=> array(0) { } ["ar_aliased_tables"]=> array(0) { } ["ar_store_array"]=> array(0) { } ["ar_caching"]=> bool(false) ["ar_cache_exists"]=> array(0) { } ["ar_cache_select"]=> array(0) { } ["ar_cache_from"]=> array(0) { } ["ar_cache_join"]=> array(0) { } ["ar_cache_where"]=> array(0) { } ["ar_cache_like"]=> array(0) { } ["ar_cache_groupby"]=> array(0) { } ["ar_cache_having"]=> array(0) { } ["ar_cache_orderby"]=> array(0) { } ["ar_cache_set"]=> array(0) { } ["username"]=> string(10) "UUUUU" ["password"]=> string(11) "XXXXXXXX" ["hostname"]=> string(11) "10.10.11.42" ["database"]=> string(8) "sugarcrm" ["dbprefix"]=> string(0) "" ["char_set"]=> string(4) "utf8" ["dbcollat"]=> string(15) "utf8_general_ci" ["autoinit"]=> bool(true) ["swap_pre"]=> string(0) "" ["port"]=> string(0) "" ["pconnect"]=> bool(true) ["conn_id"]=> object(mysqli)#23 (17) { ["affected_rows"]=> int(0) ["client_info"]=> string(48) "mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $" ["client_version"]=> int(50007) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["field_count"]=> int(0) ["host_info"]=> string(22) "10.10.11.42 via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(19) "5.1.41-3ubuntu12.10" ["server_version"]=> int(50141) ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(210) ["warning_count"]=> int(0) } ["result_id"]=> bool(false) ["db_debug"]=> bool(false) ["benchmark"]=> int(0) ["query_count"]=> int(0) ["bind_marker"]=> string(1) "?" ["save_queries"]=> bool(true) ["queries"]=> array(0) { } ["query_times"]=> array(0) { } ["data_cache"]=> array(0) { } ["trans_enabled"]=> bool(true) ["trans_strict"]=> bool(true) ["_trans_depth"]=> int(0) ["_trans_status"]=> bool(true) ["cache_on"]=> bool(false) ["cachedir"]=> string(0) "" ["cache_autodel"]=> bool(false) ["CACHE"]=> NULL ["_protect_identifiers"]=> bool(true) ["_reserved_identifiers"]=> array(1) { [0]=> string(1) "*" } ["stmt_id"]=> NULL ["curs_id"]=> NULL ["limit_used"]=> NULL ["stricton"]=> bool(false) } (Password and user values have been changed ;-) Connecting to multiple databases ? - El Forum - 06-07-2011 [eluser]InsiteFX[/eluser] Your think you sql is wrong! InsiteFX Connecting to multiple databases ? - El Forum - 06-08-2011 [eluser]spaquet[/eluser] Found the error ! String concatenation in PHP is . and not + (... ;-) and by the way I can now use Code: $query->num_rows |