Hosting & Domaining Forum

Hosting & Domaining development => Programming Discussion => Databases => Topic started by: lilyalvin on Sep 08, 2022, 09:28 AM

Title: Problem with database
Post by: lilyalvin on Sep 08, 2022, 09:28 AM
I'm racking my head, I don't understand what's wrong.
Fatal error: Uncaught exception PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'skill_shop.products' ...............functions.php on line 183

-- phpMyAdmin SQL Dump
-- version 4.9.0.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Creation time: Feb 12 2020 20:59
-- Server Version: 10.3.13-MariaDB-log
-- PHP version: 7.1.32
 
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
 
 
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
 
--
-- Database: `skill_shop`
--
 
-------------------------------------------------- --------
 
--
-- Structure of the `categories` table
--
 
CREATE TABLE `categories` (
  `id` INT(11) NOT NULL,
  `name` VARCHAR(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
--
-- Dump the `categories` table data
--
 
INSERT INTO `categories` (`id`, `name`) VALUES
(1, 'Women'),
(2, 'Men'),
(3, 'Children'),
(4, 'Bags'),
(5, 'Accessories');
 
-------------------------------------------------- --------
 
--
-- `menu` table structure
--
 
CREATE TABLE `menu` (
  `id` INT(11) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `url` VARCHAR(255) NOT NULL,
  `admin` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
--
-- Dump `menu` table data
--
 
INSERT INTO `menu` (`id`, `name`, `url`, `admin`) VALUES
(1, 'Home', '/', 0),
(2, 'New', '/?new=true', 0),
(3, 'Sale', '/?sale=true', 0),
(4, 'Delivery', '/delivery', 0),
(5, 'Products', '/admin/products', 1),
(6, 'Orders', '/admin/orders', 1);
 
-------------------------------------------------- --------
 
--
-- Structure of the `orders` table
--
 
CREATE TABLE `orders` (
  `id` INT(11) NOT NULL,
  `product_id` INT(11) NOT NULL,
  `coast` INT(11) NOT NULL,
  `surname` VARCHAR(255) DEFAULT NULL,
  `name` VARCHAR(255) NOT NULL,
  `third_name` VARCHAR(255) DEFAULT NULL,
  `phone` VARCHAR(255) NOT NULL,
  `email` VARCHAR(255) NOT NULL,
  `shipping_method` VARCHAR(255) NOT NULL,
  `city` VARCHAR(255) DEFAULT NULL,
  `street` VARCHAR(255) NOT NULL,
  `home` VARCHAR(255) NOT NULL,
  `apartment` VARCHAR(255) DEFAULT NULL,
  `payment_method` VARCHAR(255) NOT NULL,
  `comment` text NOT NULL,
  `status` tinyint(1) DEFAULT 0,
  `create_date` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP()
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
--
-- Dump the `orders` table data
--
 
INSERT INTO `orders` (`id`, `product_id`, `coast`, `surname`, `name`, `third_name`, `phone`, `email`, `shipping_method`, `city`, `street`, `home`, `apartament`, `payment_method`, `comment`, `status`, `create_date`) VALUES
(1, 66, 4850, 'Moiseenko', 'Timur', 'Fsretyumb', '+9989846846', 'tim@mail.ru', 'method_1', 'NY', 'rapr', '45', '543 ', 'Credit card', '2890oiuyhgf', 1, '2019-12-15 20:03:34'),
(10, 73, 63000, 'Gross', 'pavpvkpk', 'Fsretyumb', '+9989846846', 'tim@mail.ru', 'method_0', '', '', '', '', 'Cash ', '', 1, '2020-01-01 20:03:34'),
(13, 74, 18600, 'Gross', 'pavpvkpk', 'Fsretyumb', '+9989846846', 'tim@mail.ru', 'method_0', '', '', '', '', 'Credit card', '', 0, '2020-01-02 20:03:34'),
(14, 73, 63000, 'Gross', 'Moiseenko', 'Fsretyumb', '+9989846846', 'tim@mail.ru', 'method_0', '', '', '', '', 'Cash ', '', 1, '2019-01-12 20:03:34'),
(18, 66, 4850, 'Gross', 'Moiseenko', 'Fsretyumb', '+9989846846', 'tim@mail.ru', 'method_0', '', '', '', '', 'Cash ', '', 1, '2019-07-28 20:03:34'),
(19, 66, 4850, 'appwa', 'Moiseenko', 'Fsretyumb', '+9989846846', 'angr@ydex.ru', 'method_1', 'NY', 'lasvega', '45', '543 ', 'Credit card', 'jhgfdsa345678', 0, '2020-01-03 20:03:34'),
(20, 76, 4000, 'appwa', 'wetyui', '', '+9989846846', 'angrav-6@yandex.ru', 'method_0', '', '', '', '', ' Bank transfer', '', 0, '2020-01-09 20:03:34'),
(21, 73, 63000, 'appwa', '345678uytgfdsdf', '', '+9989846846', 'angrav-6@yandex.ru', 'method_0', '', '', '', '', ' Credit card', '', 0, '2020-01-12 20:03:34'),
(22, 73, 63000, 'Moiseenko', 'Moiseenko', '', '+9989846846', 'angrav-6@yandex.ru', 'method_2', 'Tashkent', '24 Amir Temur shoh kўchasi', ' 345', '32', 'Bank transfer', '', 1, '2019-11-26 20:03:34'),
(23, 74, 18600, 'appwa', 'pavpvkpk', '', '69985216574', 'tim@mail.ru', 'method_0', '', '', '', '', 'Credit card' , '', 0, '2020-01-11 20:03:34'),
(24, 73, 63000, 'appwa', 'pavpvkpk', 'Fsretyumb', '+9989846846', 'angrav-6@yandex.ru', 'method_3', 'NY', 'rapr', '45', '543', 'Cash', '', 0, '2020-01-12 20:03:34'),
(25, 73, 63000, 'appwa', 'pavpvkpk', 'Fsretyumb', '+9989846846', 'angrav-6@yandex.ru', 'method_3', 'NY', 'rapr', '45', '543', 'Cash', '', 0, '2019-12-28 20:03:34'),
(26, 69, 8755, 'appwa', 'pavpvkpk', '', '+9989846846', 'tim@mail.ru', 'method_1', 'NY', 'lasvega', '45', '32' , 'By credit card', '234567890prob234567890prob234567890prob', 1, '2019-10-26 20:03:34'),
(27, 5, 10000, 'check ', 'new ', 'Delivery Method', '69985216574', 'tim@mail.ru', 'method_1', 'NY', 'lasvega', '15', '52' , 'Cash', '12345678schwgnek', 0, '2020-01-12 20:03:34'),
(28, 5, 10000, 'check ', 'new ', 'delivery method', '69985216574', 'tim@mail.ru', 'method_1', 'NY', 'lasvega', '15', '52' , 'Cash', '12345678schwgnek', 0, '2019-10-12 20:03:34'),
(29, 3, 2950, ��'more', 'one more', 'check', '69985216574', 'tim@mail.ru', 'method_3', 'Tashkent', '24 Amir Temur shoh kўchasi', '45' , '543', 'Bank transfer', '2345678zshgnekucyvaprbtim', 0, '2020-01-12 20:03:34'),
(30, 3, 3690, 'check', 'new', 'delivery method', '69985216574', 'tim@mail.ru', 'method_3', 'jfg', 'lasvega', 'arp', '543' , 'Cash', '', 0, '2020-01-12 20:03:34'),
(31, 4, 4960, 'Gross', 'pavpvkpk', 'check', '69985216574', 'tim@mail.ru', 'method_0', '', '', '', '', 'Credit card ', '', 0, '2020-01-12 20:03:34'),
(32, 4, 4960, 'Gross', 'pavpvkpk', 'verification', '69985216574', 'tim@mail.ru', 'method_0', '', '', '', '', 'Credit card ', '', 0, '2020-01-12 20:03:34'),
(33, 4, 4960, 'Gross', 'pavpvkpk', 'verification', '69985216574', 'tim@mail.ru', 'method_0', '', '', '', '', 'Credit card ', '', 0, '2020-01-12 20:03:34');
 
-------------------------------------------------- --------
--
-- Structure of the `payment_method` table
--
 
CREATE TABLE `payment_method` (
  `id` INT(11) NOT NULL,
  `name` VARCHAR(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
--
-- Dump `payment_method` table data
--
 
INSERT INTO `payment_method` (`id`, `name`) VALUES
(1, 'Cash'),
(2, 'Credit card'),
(3, 'Bank transfer');
 
-------------------------------------------------- --------
 
--
-- Structure of the `products` table
--
 
CREATE TABLE `products` (
  `id` INT(11) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `price` FLOAT DEFAULT NULL,
  `new` tinyint(1) DEFAULT NULL,
  `sale` tinyint(1) DEFAULT NULL,
  `image` VARCHAR(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
--
-- Dump `products` table data
--
 
INSERT INTO `products` (`id`, `name`, `price`, `new`, `sale`, `image`) VALUES
(1, 'Pleated dress', 13700, 1, NULL, '/upload/products/product-1.jpg'),
(2, 'Shirt', 5815, NULL, 1, '/upload/products/product-2.jpg'),
(3, 'Hours', 2950, ��NULL, NULL, '/upload/products/product-3.jpg'),
(4, 'Pants', 4960, NULL, NULL, '/upload/products/product-4.jpg'),
(5, 'Red dress', 10000, 1, 1, '/upload/products/product-6.jpg'),
(6, 'Pink coat', 35030, NULL, NULL, '/upload/products/product-7.jpg'),
(7, 'Jeans', 9779, NULL, NULL, '/upload/products/product-8.jpg'),
(8, 'Boots', 3100, NULL, 1, '/upload/products/product-9.jpg'),
(9, 'Shoes', 2500, 1, NULL, '/upload/products/product-9.jpg'),
(10, 'Cocktail dress', 15050, NULL, NULL, '/upload/products/product-6.jpg'),
(11, 'Shorts', 1400, NULL, 1, '/upload/products/product-2.jpg'),
(12, 'Hours', 500, NULL, NULL, '/upload/products/product-3.jpg'),
(14, 'White coat', 27000, NULL, NULL, '/upload/products/product-5.jpg'),
(17, 'Blouse', 2450, NULL, NULL, '/upload/products/product-8.jpg'),
(18, 'NewProd', 9584, 1, 0, '/upload/products/product-1.jpg'),
(64, 'Updated product', 70575, 0, 1, '/upload/products/2019-12-18product-3.jpg'),
(65, 'Dress', 12500, 1, 0, '/upload/products/2019-12-18-product-6.jpg'),
(66, 'Jeans', 4850, 0, 1, '/upload/products/2019-12-18-product-8.jpg'),
(67, 'Blouse', 3540, 0, 1, '/upload/products/2019-12-18-product-2.jpg'),
(68, 'Pants', 5482, 0, 0, '/upload/products/2019-12-18-product-4.jpg'),
(69, 'New product', 8755, 0, 0, '/upload/products/2019-12-18-product-9.jpg'),
(70, 'Coat', 45000, 1, 1, '/upload/products/2019-12-18-product-7.jpg'),
(71, 'Bag', 2598, 0, 0, '/upload/products/2019-12-18-product-5.jpg'),
(72, 'Small bag', 2150, 0, 0, '/upload/products/2019-12-18-product-7.jpg'),
(74, 'Cocktail dress', 18600, 0, 1, '/upload/products/2019-12-18-product-6.jpg'),
(75, 'Shirt', 5482, 0, 0, '/upload/products/2019-12-18-product-2.jpg'),
(76, 'Product 272', 4000, 1, 0, '/upload/products/2019-12-19-product-8.jpg');
 
-------------------------------------------------- --------
 
--
-- Structure of the `product_categories` table
--
 
CREATE TABLE `product_categories` (
  `product_id` INT(11) NOT NULL,
  `cat_id` INT(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
--
-- Dump `product_categories` table data
--
 
INSERT INTO `product_categories` (`product_id`, `cat_id`) VALUES
(eleven),
(13),
(fifteen),
(2, 1),
(2, 2)
(2, 4),
(3, 2),
(4, 1),
(5, 5),
(6, 3),
(7, 1),
(8, 2),
(9, 3),
(10, 4)
(11, 5),
(12, 2)
(14, 5),
(18, 2),
(18, 4),
(64, 1),
(65, 1)
(66, 1)
(67, 1),
(68, 3),
(69, 5),
(70, 1)
(70, 5),
(71, 2),
(71, 3),
(71, 4),
(72, 5),
(74, 2),
(75, 3),
(76, 1),
(76, 2),
(76, 3),
(76, 4),
(76, 5);
 
-------------------------------------------------- --------
 
--
-- `role` table structure
--
 
CREATE TABLE `role` (
  `id` INT(11) NOT NULL,
  `name` VARCHAR(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
--
-- Dump `role` table data
--
 
INSERT INTO `role` (`id`, `name`) VALUES
(1, 'admin'),
(2, 'operator');
 
-------------------------------------------------- --------
 
--
-- Structure of the `shipping_method` table
--
 
CREATE TABLE `shipping_method` (
  `id` INT(11) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `coast` INT(11) NOT NULL,
  `max_order` INT(11) DEFAULT NULL,
  `desc` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
--
-- Dump `shipping_method` table data
--
INSERT INTO `shipping_method` (`id`, `name`, `coast`, `max_order`, `desc`) VALUES
(1, 'Standard Shipping', 280, 2000, 'Estimated delivery time will be around 2-7 business days, depending on delivery address.'),
(2, 'On the day of purchase', 560, NULL, 'Available to residents of Moscow within the Moscow Ring Road. Orders placed from Monday to Friday before 14:00 will be delivered on the same day from 19:00 to 23:00. Change of address delivery after placing an order is not possible.'),
(3, 'Delivery with fitting', 740, 5000, 'Delivery is possible only within Moscow (within the Moscow Ring Road) within 2-3 days. Using the "Trying before buying" service, you can receive your order and try on the ordered goods. You pay only for what suits you. The maximum number of items in an order for which fitting is available is 10 items. The time for fitting one order is 15 minutes.');
 
-------------------------------------------------- --------
 
--
-- Structure of the `users` table
--
 
CREATE TABLE `users` (
  `id` INT(11) NOT NULL,
  `login` VARCHAR(255) NOT NULL,
  `password` VARCHAR(255) NOT NULL,
  `name` VARCHAR(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
--
-- Dump `users` table data
--
 
INSERT INTO `users` (`id`, `login`, `password`, `name`) VALUES
(1, 'email@mail.ru', '$2y$10$Ee2CmNSlEHOG3zdXxgkh3.Yb1RibAYePt3AhQKwMulvWa2xlLMUzO', 'Moiseenko Timur'),
(2, 'email@yandex.ru', '$2y$10$Ee2CmNSlEHOG3zdXxgkh3.Yb1RibAYePt3AhQKwMulvWa2xlLMUzO', 'Lagutenko Ilya'),
(3, 'email@google.ru', '$2y$10$Ee2CmNSlEHOG3zdXxgkh3.Yb1RibAYePt3AhQKwMulvWa2xlLMUzO', 'Someone else');
 
-------------------------------------------------- --------
 
--
-- Structure of the `users_role` table
--
 
CREATE TABLE `users_role` (
  `user_id` INT(11) NOT NULL,
  `role_id` INT(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
--
-- Dump `users_role` table data
--
 
INSERT INTO `users_role` (`user_id`, `role_id`) VALUES
(12),
(2, 1);
 
--
-- Indexes of stored tables
--
 
--
-- Indexes of the `categories` table
--
ALTER TABLE `categories`
  ADD PRIMARY KEY(`id`);
 
--
-- Indexes of the `menu` table
--
ALTER TABLE `menu`
  ADD PRIMARY KEY(`id`);
 
--
-- Indexes of the `orders` table
--
ALTER TABLE `orders`
  ADD PRIMARY KEY(`id`);
 
--
-- Indexes of the `payment_method` table
--
ALTER TABLE `payment_method`
  ADD PRIMARY KEY(`id`);
 
--
-- Indexes of the `products` table
--
ALTER TABLE `products`
  ADD PRIMARY KEY(`id`);
 
--
-- Indexes of the `product_categories` table
--
ALTER TABLE `product_categories`
  ADD PRIMARY KEY (`product_id`,`cat_id`),
  ADD KEY `product_gategories_categories_id_fk` (`cat_id`);
 
--
-- `role` table indexes
--
ALTER TABLE `role`
  ADD PRIMARY KEY(`id`);
 
--
-- Indexes of the `shipping_method` table
--
ALTER TABLE `shipping_method`
  ADD PRIMARY KEY(`id`);
 
--
-- Indexes of the `users` table
--
ALTER TABLE `users`
  ADD PRIMARY KEY(`id`);
 
--
-- Indexes of the `users_role` table
--
ALTER TABLE `users_role`
  ADD PRIMARY KEY(`role_id`),
  ADD KEY `users_role_users_id_fk`(`user_id`);
 
--
-- AUTO_INCREMENT for saved tables
--
 
--
-- AUTO_INCREMENT for the `categories` table
--
ALTER TABLE `categories`
  MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
 
--
-- AUTO_INCREMENT for the `menu` table
--
ALTER TABLE `menu`
  MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
 
--
-- AUTO_INCREMENT for the `orders` table
--
ALTER TABLE `orders`
  MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=34;
 
--
-- AUTO_INCREMENT for `payment_method` table
--
ALTER TABLE `payment_method`
  MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
 
--
-- AUTO_INCREMENT for `products` table
--
ALTER TABLE `products`
  MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=77;
 
--
-- AUTO_INCREMENT for table `role`
--
ALTER TABLE `role`
  MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
 
--
-- AUTO_INCREMENT for `shipping_method` table
--
ALTER TABLE `shipping_method`
  MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
 
--
-- AUTO_INCREMENT for `users` table
--
ALTER TABLE `users`
  MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
 
--
-- Foreign key constraints on saved tables
--
 
--
-- Foreign key constraints on the `product_categories` table
--
ALTER TABLE `product_categories`
  ADD CONSTRAINT `product_gategories_categories_id_fk` FOREIGN KEY (`cat_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `product_gategories_products_id_fk` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
 
--
-- Foreign key constraints on the `users_role` table
--
ALTER TABLE `users_role`
  ADD CONSTRAINT `users_role_role_id_fk` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `users_role_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;
 
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

db settings:
<?php
define
('DB_DSN''mysql:host=localhost;dbname=skill_shop;charset=utf8');
define('DB_USER''root');
define('DB_PASSWORD''root');
define('DELIVERY', [
    
'method_0' => [
        
'name' => 'Pickup',
        
'discount' => 0,
        
'min_order_value' => 0,
        
'desc' => 'You will be able to pick up purchases from our warehouse at the address: Moscow g, Tverskaya st, 4 Okhotny Ryad Metro station',
    ],
    
'method_1' => [
        
'name' => 'Standard delivery',
        
'discount' => 280,
        
'min_order_value' => 2000,
        
'desc' => 'The approximate delivery time will be about 2-7 working days, depending on the delivery address.',
    ],
    
'method_2' => [
        
'name' => 'On the day of purchase',
        
'discount' => 560,
        
'min_order_value' => 0,
        
'desc' => 'is available for residents of Moscow within the Moscow Ring Road. Orders placed from Monday to Friday until 14:00 
        they will be delivered on the same day from 19:00 to 23:00. It is not possible to change the delivery address after placing an order.'
,
    ],
    
'method_3' => [
        
'name' => 'Delivery with fitting',
        
'discount' => 740,
        
'min_order_value' => 5000,
'desc' => 'Delivery is possible only in Moscow (within the MKAD) within 2-3 days. Using the service 
        "Fitting before purchase", you can receive your order and try on the ordered goods. You only pay
for what suits you. The maximum number of items in the order for which fitting is available is 10 items. 
        The time for fitting one order is 15 minutes.'
,
    ]
]);
?>

Title: Re: Problem with database
Post by: Austin on Sep 08, 2022, 10:03 AM
The `products` table is missing from the `skill_shop` database.
Title: Re: Problem with database
Post by: jameswilliam723 on Nov 10, 2022, 05:58 AM
Every PHP user, even if he is not a programmer, should develop the habit of reading error messages. And - importantly - read the whole thing, not just the first couple of words.
Usually, the error message describes in detail what the problem is.

For example, in this case, we are told that the user is trying to log in with the name DATABASE_USERNAME, which looks quite unusual, and looks more like the name of a constant than the name of the database.

We look at the calling code and make sure that yes - the constant is taken in quotation marks for some reason, and as a result, not its value is transmitted, but literally the string DATABASE_USERNAME.

If you remove the quotes, the connection to the PDO will be successful.