php oracle integration where to begin? [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
We have an up and running server with php and mysql. We want to use Oracle db as well as the mysql(for performance issues).
What can be the steps to implement oracle to php? Can you give me a head start on where to begin?

You need to use oci driver for oracle connectivity with php, You can use 2 different way for php & oracle connectivity. First way to enable php_pdo_oci extension and 2nd install php_oci8 or php_oci8_11g depends on oracle version. For the starting purpose you can check you connection with sample code below for php_pdo_oci extension.
$tns ='tns:port/dbname';
$db_username = 'username';
$db_password = 'password';
try{
$db = new PDO("oci:dbname=".$tns,$db_username,$db_password,array(PDO::ERRMODE_EXCEPTION => true));
}
catch (PDOException $e)
{
die("getConnection: " .$e->getMessage());
}
$stmt = $db->query("SELECT FIELD_NAME FROM TABLE WHERE ID=1");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo '<pre>';
print_r($row);

If want to use core php you can use here
Else if you can use CodeIgnitor framework which provide ORM support with many database like mysql, oracle, etc...

Related

PHP & SQLite connect [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
Ok so I'm getting an error for failing to connect to SQLite which is most likely from the mysqli_connect(). My question is what exactly is the user name and password, is it an administrative one or is this from the database? I'm new to database.
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
"my_user" and "my_password" is suppose to be what exactly? I have localhost connected to 127.0.0.1 and "my_db" I just put as the database name I used and created.
You are confusing mysql with sqlite and your connection using mysqli() command will not work then. You could instead use open('nameofthedbfilehere') open a stand alone file in sqlite.. See tutorial here.
User is the administrative user you made when you create the database.
And password is the database password you entered when you created the database.

What is the purpose of $connect in mysqli_real_escape_string($connect, $username)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
So I was wondering, if I need to escape a string, why do I need to connect to my database first?
I tried something like:
$username = mysqli_real_escape_string($username);
But that didn't work, it requires 2 parameters(one of which is the $connect) Could y ou please explain the purpose of connecting to the database first and then escaping it?
I would also like to know how would that be efficient/applied in a registration page as well?
Thanks.
Per the docs:
Security: the default character set
The character set must be set either at the server level, or with the API function mysqli_set_charset() for it to affect mysqli_real_escape_string(). See the concepts section on character sets for more information.
And therein lies the reason for having the connection: how to escape your string depends on the server's character set.

run database sql query from php just like from phpmyadmin [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Does anyone here have a ready made PHP file (script) which can connect to the database (by inserting, host,dabasename,user,pas) and then be used to run SQL queries. For example by putting the query in a variable and then run it. This would be the same kind of queries which can be run from phpmyadmin.
If you're asking how to use a MySQL database in PHP, I suggest learning about PDO:
<?php
$pdo = new pdo("mysql:host=localhost,dbname=YourDatabase","Username","Password");
?>
and submitting would go as follow:
<?php
//Unsafe
$unsafeSubmit = $pdo->query("INSERT INTO `myTable` VALUES(`id`,'".$variable1."','".$variable2."')");
//Safe
$submitInformation = $pdo->prepare("INSERT INTO `myTable` VALUES(`id`,:varOne,:varTwo)");
$submitInformation->bindValue(":varOne",$variable1);
$submitInformation->bindValue(":varTwo",$variable2);
$submitInformation->execute();
?>
With reading it with the SELECT query.
I suggest reading the documentation on PHP.NET
You should read up on how to do this, there are multiple ways like PDO or MySQLi
documentation mysqli on php.net
documentation pdo on php.net
These are two very well used, well supported and built in libraries in PHP which will allow you to execute queries from PHP. It's one of the first things I learned at school (deprecated mysql) so you should be fine reading up on those two.
Ok i found a quick solution using Sidney Liebrand links. Thanks
<?php
$user="username";
$password="password";
$database="database";
mysql_connect(localhost,$user,$password);
#mysql_select_db($database) or die( "Unable to select database");
$query= /* query */ "";
mysql_query($query);
mysql_close();
?>

MySQL determining which database to use [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am a beginner with MySQL. I have this code and I would like an explanation on how the function knows which database to use since $conn and $db are defined?
$conn = mysql_connect("localhost","primeb5_mysql","***");
$db = mysql_select_db("primeb5_unigis");
$query = "SELECT * FROM lesson3";
$result = mysql_query($query);"
From PHP manual:
http://php.net/manual/en/function.mysql-query.php
The MySQL connection. If the link identifier is not specified, the
last link opened by mysql_connect() is assumed.
So, In case you don't specify the connection (second parameter) to the mysql_query() function, the last one is used.
On the side note, I'd like to notify you, that mysql_* functions have been deprecated in PHP 5.5.0. Do not use them, because if you do, your site might stop working soon.
mysql is deprecated use mysqli or PDO instead
You don't have to use an PHP function to select your database
just use this
mysqli_query("SELECT * FROM primeb5_unigis.lesson3");
or join example between multiple databases after ON missing...
mysqli_query("SELECT * FROM database1.table1 INNER JOIN database2.table2 ON ...");
edit
i think topicstarter means connection to database but i leave the answer could be helpfull

mysql_real_escape_string is not working in one server [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
<?php echo mysql_real_escape_string('tientrer') ;?>
The above code is return an empty string in one server but is working fine in other servers. Why is it so?
Wildly random guess:
You are not connecting to a database using mysql_connect. mysql_real_escape_string needs a database connection to do its job (because you are escaping for the database; you are escaping this for a database query, right?!). If no connection exists yet, it'll try to establish one automatically using a standard username and password. On one server this standard password works, on another it doesn't.
you are escaping a string ?
you mean maybe like that
<?php echo mysql_real_escape_string($tientrer) ;?>
to escape the variable tientrer if its a variable.
EDIT:
then maybe the server which not working maybe the mysql is deprecated there , try change to mysqli or pdo

Categories