What Should I do I am getting Fatal Error from this code? - xampp

Getting this error:-
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) in C:\WEB-PROJECT\xampp\htdocs\facebook\core\database\connection.php:8 Stack trace: #0 C:\WEB-PROJECT\xampp\htdocs\facebook\core\database\connection.php(8): PDO->__construct('mysql:host=127....', 'root', '') #1 C:\WEB-PROJECT\xampp\htdocs\facebook\core\load.php(3): include('C:\WEB-PROJECT\...') #2 C:\WEB-PROJECT\xampp\htdocs\facebook\sign.php(4): require('C:\WEB-PROJECT\...') #3 {main} thrown in C:\WEB-PROJECT\xampp\htdocs\facebook\core\database\connection.php on line 8
From this code:-
<?php
$hostDetails = 'mysql:host=127.0.0.1; dbname=facebook; charset=utf8mb4';
$userAdmin = 'root';
$pass = '';
try{
$pdo = new PDO($hostDetails,$userAdmin,$pass);
} catch(PDOExecption $e){
echo 'Connection error!' . $e->getMessage();
}
?>

Related

Laravel SQL server connection

I have laravel 7.3, and sql server 16,
i need to connect to the database sql server, but i have this error :
SQLSTATE = 08001 error- No connection could be made because the target machine actively refused it.
and there is the .env file
DB_CONNECTION=sqlsrv
DB_HOST=127.0.0.1/instancename
DB_PORT=1433
DB_DATABASE=Database
DB_USERNAME=sa
DB_PASSWORD=12345678`
But when i use the simple php file to connect the connexion is ok.
this is the php script :
<?php
$serverName = "127.0.0.1/instancename";
$connectionInfo = array( "Database"=>"Database", "UID"=>"sa", "PWD"=>"12345678");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connexion établie.<br />";
}else{
echo "La connexion n'a pu être établie.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
Manny thanks for your help

Xampp localhost - Error!: SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
Improve this question
I'm trying to load my htdocs/pdoexample/index.php
<?php
$host = 'localhost';
$user = 'root';
$password = '123456';
$dbname = 'pdoposts';
// Set DSN (Data Source Name)
$dsn = 'mysql:host='. $host .';dbname='. $dbname;
// Creat a PDO instance
try {
$dsn = "mysql:dbname={$dbname};host={$host}";
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
// # PDO QUERY
$stmt = $pdo->query('SELECT * FROM posts');
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
echo $row['title']. '<br>';
}
?>
to see the error, and ran http://localhost/pdoexample/, I got this error below.
Error!: SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
UPDATE / SOLUTION --> I found out that i did not set any database password so I changed "$password = '123456';" to "$password = '';"

unlink(\public\images/backend_images/category_images/): Permission denied

I am trying to delete images from DB, but it shows below error:
unlink(\public\images/backend_images/category_images/): Permission denied
Can anyone tell me where is a mistake in my code?
public function destroy(Category $category)
{
$image = $category->image;
$image = public_path("images/backend_images/category_images/$image");
if (file_exists($image)) unlink($image);
$category->delete();
return redirect(route('admin.category.index'))->with('flash_message_error', 'Category has been Deleted successfully');
}

Fatal error: Uncaught SoapFault exception: [Client] Function ("call")

I'm using SOAP API to print the product information using it's SKU in Magento. Code is working fine on local server but it's throws fatal error on live server Fatal error: Uncaught SoapFault exception: [Client] Function ("call") is not a valid method for this service....
//require_once("../app/Mage.php");
require_once(__DIR__ . '/app/Mage.php');
Mage::app();
$mage_url = 'http://mylivedomain.com/api/v2_soap/?wsdl' ;
$mage_user = 'username';
$mage_api_key = 'password';
// Initialize the SOAP client
$soap = new SoapClient( $mage_url );
// Login to Magento
$session_id = $soap->login( $mage_user, $mage_api_key );
$resources = $soap->resources( $session_id );
$product = $soap->call( $session_id, 'catalog_product.info', ergo10000012 );
print_r ($product);
This is becuase the SOAP version and the web-service call methods are mismatching...
The URL should be : $mage_url = 'http://mylivedomain.com/api/soap/?wsdl' ;

Google Analytics Api Error

I am trying to make a call to get data from Google Analytics.
<?php
require_once 'lib/apiClient.php';
require_once 'lib/contrib/apiAnalyticsService.php';
session_start();
$client = new apiClient();
$service = new apiAnalyticsService($client);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
$accounts = $service->management_accounts->listManagementAccounts();
print "<h1>Accounts</h1><pre>" . print_r($accounts, true) . "</pre>";
try {
$data = $service->data_ga->get('ga:29214712', '2012-01-01', '2012-01-15',
'ga:visits', array('dimensions' => 'ga:source,ga:keyword', 'sort' =>
'-ga:visits,ga:source', 'filters' => 'ga:medium==organic', 'max-results' => '25'));
}
catch (apiServiceException $e) {
echo $e->getCode();
print_r($data);
}
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
After Wrapping the code in the TRY Catch Block i am getting the following error
403
Error calling GET https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A29214712&start-date=2012-01-01&end-date=2012-01-15&metrics=ga%3Avisits: (403) Forbidden
( ! ) Notice: Undefined variable: data in
C:\wamp\www\gitgrow\index.php on line 43
Note: I have granted the permission and have forced the Profile ID to test it.
The 403 error you're getting means the authorized user doesn't have access to the ga:29214712 reporting profile that is defined in your query.
Take a look at the HelloAnalyticsAPI.php sample in the examples/analytics/demo directory, and make sure you can connect to the API:
http://code.google.com/p/google-api-php-client/source/browse/#svn%2Ftrunk%2Fexamples%2Fanalytics%2Fdemo
Also, take a look at the Google Analytics developer guide. It will describe how you can obtain the correct profile IDs:
https://developers.google.com/analytics/devguides/reporting/core/v3/#user_reports

Resources