I am developing a application in Codeigniter Framework and I have been created a model with name "Surveyor_model" and I am trying to execute query but it is not executing and give a message "table or view does not exist."
I have been create a model in codeigniter with name " Surveyor_model"
and I am trying to execute a query with syntax
$this->oracle_db->get('users_surveyor');
But it is showing a query as given below
select * from "users_surveyor"
and showing a error message "Table or view does not exist"
I want to remove double quotation from a query as given below
select * from "users_surveyor"
so please tell me how can I remove double quotation.
And my I am also showing a database config and please see as given below
$dbtns = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.9.1.217)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = orcl) (SID = orcl)))";
$active_group = 'oracle';
$query_builder = TRUE;
$db['oracle'] = array(
'dsn' => '',
'hostname' => $dbtns,
//'username' => 'igistest',
//'password' => 'igistest',
'username' => 'cwms',
'password' => 'cwms321',
'database' => 'orcl',
'dbdriver' => 'oci8',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Form this post you can use.
SET GLOBAL SQL_MODE=ANSI_QUOTES;
For more information you can read this article Link.
Related
I'm new to Codeigniter PHP framework. When I'm testing my application I get 'Unknown database db_name' error. I have browsed through several sites but didn't found solution for the problem as I'm trying the same to connect with wamp's mysql database. Any help would be appreciable.
Following is database.php in config folder: image describing Test database:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'test',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array()
);
I was getting same error when i installed new wampserver 3.2.0, it is an evil it installs MariaDB by default and port 3306 is assigned to it , you cannot even change it. I think codeigniter/php tries to connect to this port by default.
I used following , it worked for me i.e. hostname => 'localhost:3308'
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost:3308',
'username' => 'root',
'password' => '',
'database' => 'soft',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
That's what i did to handle whether db exists or not :
First Change this in application/config/database.php
'db_debug' => (ENVIRONMENT !== 'production')
to
'db_debug' => FALSE;
Then add these two in your controller
$this->load->dbforge();
$this->load->dbutil();
Then check it in your method
if( $this->dbutil->database_exists($this->db->database))
{
echo 'Database Already Exists';
}
else
{
if($this->dbforge->create_database($this->db->database))
{
echo 'Database created successfully !';
}else
{
print_r($this->db->error());
/*
Array (
[code] => 1007
[message] => Can't create database 'my_db'; database exists
)
*/
}
}
I was too getting this error. There are 2 fields in application/config/database.php file that should match up with your actual database:
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
Make sure, the actual DB is of the same type & char_set as mentioned in the above file.
I'm new to Codeigniter PHP framework. When I'm testing my application I get 'Unknown database db_name' error. I have browsed through several sites but didn't found solution for the problem as I'm trying the same to connect with wamp's mysql database. Any help would be appreciable.
Following is database.php in config folder: image describing Test database:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'test',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array()
);
I was getting same error when i installed new wampserver 3.2.0, it is an evil it installs MariaDB by default and port 3306 is assigned to it , you cannot even change it. I think codeigniter/php tries to connect to this port by default.
I used following , it worked for me i.e. hostname => 'localhost:3308'
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost:3308',
'username' => 'root',
'password' => '',
'database' => 'soft',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
That's what i did to handle whether db exists or not :
First Change this in application/config/database.php
'db_debug' => (ENVIRONMENT !== 'production')
to
'db_debug' => FALSE;
Then add these two in your controller
$this->load->dbforge();
$this->load->dbutil();
Then check it in your method
if( $this->dbutil->database_exists($this->db->database))
{
echo 'Database Already Exists';
}
else
{
if($this->dbforge->create_database($this->db->database))
{
echo 'Database created successfully !';
}else
{
print_r($this->db->error());
/*
Array (
[code] => 1007
[message] => Can't create database 'my_db'; database exists
)
*/
}
}
I was too getting this error. There are 2 fields in application/config/database.php file that should match up with your actual database:
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
Make sure, the actual DB is of the same type & char_set as mentioned in the above file.
i have this project created by php and mysql but i have error
Filename: C:\xampp\htdocs\demo\system\database\DB_driver.php
Line Number: 124
and uploaded my project to solve this with very thanks for all team .
http://www.webchinupload.com/f/2019-05/ebae9eaf2a9655eb442da8a9e648da3e.rar
my error in line 124
$this->conn_id = ($this->pconnect == false) ? $this->db_connect() : $this->db_pconnect();
// No connection resource? Throw an error
if ( ! $this->conn_id)
{
log_message('error', 'Unable to connect to the database');
if ($this->db_debug)
{
$this->display_error('db_unable_to_connect');
}
return FALSE;
}
Change hostname to localhost
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = ''; #database password
$db['default']['database'] = 'e-frosh_test';
Check your application/config/database.php
In codeigniter framework
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'root',//Put Your db passwaord
'database' => 'e-frosh_test',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
i need your help.
access via browser, error like this:
in Oci8.php (line 460)
at Oci8->connect('(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.31)(PORT = 1521)) (CONNECT_DATA =(SID = orcl)))', 'device', '123456', array(2, 2, 0, 'charset' => 'ZHS16GBK'), 'ZHS16GBK')
in Oci8.php (line 78)
at Oci8->__construct('(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.31)(PORT = 1521)) (CONNECT_DATA =(SID = orcl)))', 'device', '123456', array(2, 2, 0, 'charset' => 'ZHS16GBK'))
in OracleConnector.php (line 204)
at OracleConnector->createConnection('(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.31)(PORT = 1521)) (CONNECT_DATA =(SID = orcl)))', array('driver' => 'oracle', 'tns' => '', 'host' => '192.168.1.31', 'port' => '1521', 'database' => 'orcl', 'username' => 'device', 'password' => '123456', 'charset' => 'ZHS16GBK', 'prefix' => '', 'prefix_schema' => '', 'name' => 'oracle'), array(2, 2, 0, 'charset' => 'ZHS16GBK'))
in OracleConnector.php (line 35)
at OracleConnector->connect(array('driver' => 'oracle', 'tns' => '', 'host' => '192.168.1.31', 'port' => '1521', 'database' => 'orcl', 'username' => 'device', 'password' => '123456', 'charset' => 'ZHS16GBK', 'prefix' => '', 'prefix_schema' => '', 'name' => 'oracle'))
in Oci8ServiceProvider.php (line 49)
Use the php script below,return "Connect Oracle successfully!"
<?php
$conn = oci_connect('device', '123456', '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.31)(PORT=1521))(CONNECT_DATA=(SID=orcl)))', 'ZHS16GBK');
if (!$conn) {
$e = oci_error();
print htmlentities($e['message']);
exit;
}else {
echo "Connect Oracle successfully!";
}
?>
my environment:
mac pro version:10.12.6 (16G29)
php:PHP 7.1.4 (cli) (built: May 6 2017 10:02:00) ( NTS )
laravel:Laravel Framework 5.4.33
xcode:Version 8.3.3 (8E3004b)
oracle: 11g
my .env file
DB_CONNECTION=oracle
DB_HOST=192.168.1.31
DB_PORT=1521
DB_DATABASE=orcl
DB_USERNAME=device
DB_PASSWORD=123456
DB_TNS=
DB_CHARSET=ZHS16GBK
I am doing php in Codeigniter framework.Always Codeigniter support default persistent connections.I don't want to use that connection.I need to connect manually.Is it possible in Codeigniter? If anybody know please help me to go forward.I need little bit explanation also please.
if you want not persistent connection, set up the config file.
$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
$this->load->database($config);
You can read more in http://codeigniter.com/user_guide/database/connecting.html
You have to update the file in application/config/databse.php
The values depend on the specific environment.For example, when using SQLite you will not need to supply a username or password, and the database name will be the path to your database file.
If you are using xampp server keep the password field blank.
$active_group ='default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'test',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);