+ 37
Hey guys I need a help to understand how php is connected with sql (Oracle) to make an database of hospital management system.
guys please suggest me how to do it and how I can make their database and connect that at front end I want to understand that so please post your suggestions and suggest me how can I make that good looking 😊😊
27 Answers
+ 32
@Vansh - I would like to generalize your post:
If you want to make a program that does anything, just do some research, see which language is most appropriate for the task, learn it, then write the code with the correct syntax, run the compiler (or pass the code to an interpreter) and that's it 😃
😂😂😂
PS: BTW that answers about 99% of all programming related questions in here.
+ 21
for local machine
<?php
$host='localhost';
$user='user_name';
$pswrd='pswrd';
$db='database_name';
$conn=mysqli_connect($host,$user,$pswrd,$db);
+ 12
Hi friends,
You want to connect your php file to your database okk....... so first you want to make your database by SQL than you have to make a PHP file which extension is index.php and than you have to type the code to connect your database with PHP file and connect your php document to your HTML
that's it . any query type your query and reply me.
+ 11
Create a sub-domain name in 000webhostapp.com they provide you with the database and many more features. You could manage database using phpmyadmin. Create a Database and Table with MySQL Queries insert datas into the table with the help of queries.
To show the datas in the database you've to connect to the database using server sided scripting languages such as php, asp.net, node.js, etc., Then using SELECT query you could display the datas. For example, in PHP you'll echo the datas in HTML and design & anim be made by JS and CSS. You could insert data to the SQL table through web page too by using php.
code for database connection.
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'username');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'db_name');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
+ 10
I have written a script, that will connect a SQL Database with PHP.
https://code.sololearn.com/wx86CoTzicV1/?ref=app
+ 8
@Scooby please tell me😊😊
+ 7
thanks @All for your suggestion guys😊😊
+ 6
i made many asp.net web page that holds database
but never try for php
if anything need about asp.net i'm here ☺
+ 6
Hi, i would suggest using PDO. All the above examples are outdated and you should really be building for PHP 7+.
Here is a simple db-config class you could use.
class Database
{
private $host = “localhost”;
private $db_name = "XXXX";
private $username = “XXXX”;
private $password = "XXXX";
public $conn;
public function dbConnection()
{
$this->conn = null;
try
{
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $exception)
{
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
Then you could require this db-config page and and include another page with the below classes and functions detailed below.
private $conn;
public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}
public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}
+ 5
i never try for php@gawen
+ 5
First install wamserver or xamp
then start the applications
then go to localhost/phpmyadmin in your web browser to create a database by click on create
then add a table into database
then crate a php file and save it into htdocs for xamp if using wamp then save it in www folder by name index.php
code for connecting with database
<?php
$hname = 'hostname'
$dbname = 'your_database_name'
$password = 'your_database_password'
$see = 'server'
$dbconnect = mysqli connect string($hname, $dbname, $password, $see);
?>
then use database queries to insert update or delete data in database
+ 3
if you are using wamp or xampp server, you can connect your php to your database by writing this code
<?php
$hname = 'hostname'
$dbname = 'your_database_name'
$pwd = 'your_database_password'
$see = 'server'
$dbconnect = mysqli connect string(trim($hname, $dbname, $pad, $see));
+ 3
If you know PHP and SQL the you need to learn about making projects 😊 Connecting to Database in php is not so hard anyway. PDO is the best solution but MySQLi is also available for you 😄
+ 2
I second Nikolay's post ... I don't know how many examples there are out there, but there's a whole friggin lot. don't be lazy... do some research...
In fact it takes more effort to write a post here and ask the question than it does to do some research and find the answer.
+ 2
no shortcuts .. you need to learn and understand.. you may find alot of tutorials but without giving yourself some time to understand the concepts you will face a lot of troubles
+ 2
I suggest you go read all comments here then go learn them in youtube, trust me videos are much better than reading tutorial. My biggest advice for you is take a paper and pen and draw a flowchart of your system, if you don't know how to make flowchart google how, it's pretty easy. I've built many websites and I found out that having a flowchart is much more important than knowing the codes.
+ 1
$h = 'localhost'; //this is address of your sql server. In most cases is 'localhost'
$u = 'username'; // your username in sql server
$p = 'password'; // your password
$d = 'database'; // your db name
$connection = new mysqli($h, $u, $p, $d); // here we connect to database and variable $connection is your database connection now
if ($connection->connect_error) die($connection->connect_error); // if it's something wrong with your db connection, this line terminates your script and writes you the error message
// then you can write sql query
$result = $connection->query("SELECT * FROM tablename"); // now $result contains the answer from sql server. Then you must work with $result variable to extract data.
+ 1
hello
im
Weronika